From 381c670894ba7c1dd7d99cb56d509414abe47ab2 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Fri, 25 Aug 2017 13:50:34 +0200 Subject: [PATCH] MDL-59265 mlbackend: Splitting up predictor interface in 2 --- .../classes/{predictor.php => classifier.php} | 46 +------ analytics/classes/predictor.php | 153 ++++++--------------- analytics/classes/{predictor.php => regressor.php} | 46 +------ lib/mlbackend/php/classes/processor.php | 2 +- lib/mlbackend/python/classes/processor.php | 2 +- 5 files changed, 52 insertions(+), 197 deletions(-) copy analytics/classes/{predictor.php => classifier.php} (63%) rewrite analytics/classes/predictor.php (61%) copy analytics/classes/{predictor.php => regressor.php} (63%) diff --git a/analytics/classes/predictor.php b/analytics/classes/classifier.php similarity index 63% copy from analytics/classes/predictor.php copy to analytics/classes/classifier.php index 277c6a96dd2..be0d3a09ae1 100644 --- a/analytics/classes/predictor.php +++ b/analytics/classes/classifier.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Predictions processor interface. + * Classifier interface. * * @package core_analytics * @copyright 2017 David Monllao {@link http://www.davidmonllao.com} @@ -27,20 +27,13 @@ namespace core_analytics; defined('MOODLE_INTERNAL') || die(); /** - * Predictors interface. + * Classifier interface. * * @package core_analytics * @copyright 2016 David Monllao {@link http://www.davidmonllao.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -interface predictor { - - /** - * Is it ready to predict? - * - * @return bool - */ - public function is_ready(); +interface classifier extends predictor { /** * Train this processor classification model using the provided supervised learning dataset. @@ -73,37 +66,4 @@ interface predictor { * @return \stdClass */ public function evaluate_classification($uniqueid, $maxdeviation, $niterations, \stored_file $dataset, $outputdir); - - /** - * Train this processor regression model using the provided supervised learning dataset. - * - * @param string $uniqueid - * @param \stored_file $dataset - * @param string $outputdir - * @return \stdClass - */ - public function train_regression($uniqueid, \stored_file $dataset, $outputdir); - - /** - * Estimates linear values for the provided dataset samples. - * - * @param string $uniqueid - * @param \stored_file $dataset - * @param mixed $outputdir - * @return void - */ - public function estimate($uniqueid, \stored_file $dataset, $outputdir); - - /** - * Evaluates this processor regression model using the provided supervised learning dataset. - * - * @param string $uniqueid - * @param float $maxdeviation - * @param int $niterations - * @param \stored_file $dataset - * @param string $outputdir - * @return \stdClass - */ - public function evaluate_regression($uniqueid, $maxdeviation, $niterations, \stored_file $dataset, $outputdir); - } diff --git a/analytics/classes/predictor.php b/analytics/classes/predictor.php dissimilarity index 61% index 277c6a96dd2..4b4548b4084 100644 --- a/analytics/classes/predictor.php +++ b/analytics/classes/predictor.php @@ -1,109 +1,44 @@ -. - -/** - * Predictions processor interface. - * - * @package core_analytics - * @copyright 2017 David Monllao {@link http://www.davidmonllao.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace core_analytics; - -defined('MOODLE_INTERNAL') || die(); - -/** - * Predictors interface. - * - * @package core_analytics - * @copyright 2016 David Monllao {@link http://www.davidmonllao.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -interface predictor { - - /** - * Is it ready to predict? - * - * @return bool - */ - public function is_ready(); - - /** - * Train this processor classification model using the provided supervised learning dataset. - * - * @param string $uniqueid - * @param \stored_file $dataset - * @param string $outputdir - * @return \stdClass - */ - public function train_classification($uniqueid, \stored_file $dataset, $outputdir); - - /** - * Classifies the provided dataset samples. - * - * @param string $uniqueid - * @param \stored_file $dataset - * @param string $outputdir - * @return \stdClass - */ - public function classify($uniqueid, \stored_file $dataset, $outputdir); - - /** - * Evaluates this processor classification model using the provided supervised learning dataset. - * - * @param string $uniqueid - * @param float $maxdeviation - * @param int $niterations - * @param \stored_file $dataset - * @param string $outputdir - * @return \stdClass - */ - public function evaluate_classification($uniqueid, $maxdeviation, $niterations, \stored_file $dataset, $outputdir); - - /** - * Train this processor regression model using the provided supervised learning dataset. - * - * @param string $uniqueid - * @param \stored_file $dataset - * @param string $outputdir - * @return \stdClass - */ - public function train_regression($uniqueid, \stored_file $dataset, $outputdir); - - /** - * Estimates linear values for the provided dataset samples. - * - * @param string $uniqueid - * @param \stored_file $dataset - * @param mixed $outputdir - * @return void - */ - public function estimate($uniqueid, \stored_file $dataset, $outputdir); - - /** - * Evaluates this processor regression model using the provided supervised learning dataset. - * - * @param string $uniqueid - * @param float $maxdeviation - * @param int $niterations - * @param \stored_file $dataset - * @param string $outputdir - * @return \stdClass - */ - public function evaluate_regression($uniqueid, $maxdeviation, $niterations, \stored_file $dataset, $outputdir); - -} +. + +/** + * Predictions processor interface. + * + * @package core_analytics + * @copyright 2017 David Monllao {@link http://www.davidmonllao.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core_analytics; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Predictors interface. + * + * @package core_analytics + * @copyright 2016 David Monllao {@link http://www.davidmonllao.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +interface predictor { + + /** + * Is it ready to predict? + * + * @return bool + */ + public function is_ready(); +} diff --git a/analytics/classes/predictor.php b/analytics/classes/regressor.php similarity index 63% copy from analytics/classes/predictor.php copy to analytics/classes/regressor.php index 277c6a96dd2..c2d2a89abc5 100644 --- a/analytics/classes/predictor.php +++ b/analytics/classes/regressor.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Predictions processor interface. + * Regressors interface. * * @package core_analytics * @copyright 2017 David Monllao {@link http://www.davidmonllao.com} @@ -27,52 +27,13 @@ namespace core_analytics; defined('MOODLE_INTERNAL') || die(); /** - * Predictors interface. + * Regressors interface. * * @package core_analytics * @copyright 2016 David Monllao {@link http://www.davidmonllao.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -interface predictor { - - /** - * Is it ready to predict? - * - * @return bool - */ - public function is_ready(); - - /** - * Train this processor classification model using the provided supervised learning dataset. - * - * @param string $uniqueid - * @param \stored_file $dataset - * @param string $outputdir - * @return \stdClass - */ - public function train_classification($uniqueid, \stored_file $dataset, $outputdir); - - /** - * Classifies the provided dataset samples. - * - * @param string $uniqueid - * @param \stored_file $dataset - * @param string $outputdir - * @return \stdClass - */ - public function classify($uniqueid, \stored_file $dataset, $outputdir); - - /** - * Evaluates this processor classification model using the provided supervised learning dataset. - * - * @param string $uniqueid - * @param float $maxdeviation - * @param int $niterations - * @param \stored_file $dataset - * @param string $outputdir - * @return \stdClass - */ - public function evaluate_classification($uniqueid, $maxdeviation, $niterations, \stored_file $dataset, $outputdir); +interface regressor extends predictor { /** * Train this processor regression model using the provided supervised learning dataset. @@ -105,5 +66,4 @@ interface predictor { * @return \stdClass */ public function evaluate_regression($uniqueid, $maxdeviation, $niterations, \stored_file $dataset, $outputdir); - } diff --git a/lib/mlbackend/php/classes/processor.php b/lib/mlbackend/php/classes/processor.php index f6a2922b06b..99458a140c4 100644 --- a/lib/mlbackend/php/classes/processor.php +++ b/lib/mlbackend/php/classes/processor.php @@ -38,7 +38,7 @@ use Phpml\ModelManager; * @copyright 2016 David Monllao {@link http://www.davidmonllao.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class processor implements \core_analytics\predictor { +class processor implements \core_analytics\classifier, \core_analytics\regressor { /** * Size of training / prediction batches. diff --git a/lib/mlbackend/python/classes/processor.php b/lib/mlbackend/python/classes/processor.php index 570c91e767a..84889e21235 100644 --- a/lib/mlbackend/python/classes/processor.php +++ b/lib/mlbackend/python/classes/processor.php @@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2016 David Monllao {@link http://www.davidmonllao.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class processor implements \core_analytics\predictor { +class processor implements \core_analytics\classifier, \core_analytics\regressor { /** * The required version of the python package that performs all calculations. -- 2.11.4.GIT