Php predictions processor
Copyright: | 2016 David Monllao {@link http://www.davidmonllao.com} |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 551 lines (20 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
processor:: (16 methods):
is_ready()
clear_model()
delete_output_dir()
train_classification()
classify()
evaluate_classification()
get_evaluation_result_object()
load_classifier()
train_regression()
estimate()
evaluate_regression()
export()
import()
get_model_filepath()
extract_metadata()
instantiate_algorithm()
is_ready() X-Ref |
Checks if the processor is ready to use. return: bool |
clear_model($uniqueid, $modelversionoutputdir) X-Ref |
Delete the stored models. return: null param: string $uniqueid param: string $modelversionoutputdir |
delete_output_dir($modeloutputdir, $uniqueid) X-Ref |
Delete the output directory. return: null param: string $modeloutputdir param: string $uniqueid |
train_classification($uniqueid, \stored_file $dataset, $outputdir) X-Ref |
Train this processor classification model using the provided supervised learning dataset. return: \stdClass param: string $uniqueid param: \stored_file $dataset param: string $outputdir |
classify($uniqueid, \stored_file $dataset, $outputdir) X-Ref |
Classifies the provided dataset samples. return: \stdClass param: string $uniqueid param: \stored_file $dataset param: string $outputdir |
evaluate_classification($uniqueid, $maxdeviation, $niterations, \stored_file $dataset,$outputdir, $trainedmodeldir) X-Ref |
Evaluates this processor classification model using the provided supervised learning dataset. During evaluation we need to shuffle the evaluation dataset samples to detect deviated results, if the dataset is massive we can not load everything into memory. We know that 2GB is the minimum memory limit we should have (\core_analytics\model::heavy_duty_mode), if we substract the memory that we already consumed and the memory that Phpml algorithms will need we should still have at least 500MB of memory, which should be enough to evaluate a model. In any case this is a robust solution that will work for all sites but it should minimize memory limit problems. Site admins can still set $CFG->mlbackend_php_no_evaluation_limits to true to skip this 500MB limit. return: \stdClass param: string $uniqueid param: float $maxdeviation param: int $niterations param: \stored_file $dataset param: string $outputdir param: string $trainedmodeldir |
get_evaluation_result_object(\stored_file $dataset, $scores, $maxdeviation) X-Ref |
Returns the results objects from all evaluations. return: \stdClass param: \stored_file $dataset param: array $scores param: float $maxdeviation |
load_classifier($outputdir) X-Ref |
Loads the pre-trained classifier. return: \Phpml\Classification\Linear\LogisticRegression param: string $outputdir |
train_regression($uniqueid, \stored_file $dataset, $outputdir) X-Ref |
Train this processor regression model using the provided supervised learning dataset. return: \stdClass param: string $uniqueid param: \stored_file $dataset param: string $outputdir |
estimate($uniqueid, \stored_file $dataset, $outputdir) X-Ref |
Estimates linear values for the provided dataset samples. return: void param: string $uniqueid param: \stored_file $dataset param: mixed $outputdir |
evaluate_regression($uniqueid, $maxdeviation, $niterations, \stored_file $dataset,$outputdir, $trainedmodeldir) X-Ref |
Evaluates this processor regression model using the provided supervised learning dataset. return: \stdClass param: string $uniqueid param: float $maxdeviation param: int $niterations param: \stored_file $dataset param: string $outputdir param: string $trainedmodeldir |
export(string $uniqueid, string $modeldir) X-Ref |
Exports the machine learning model. return: string The path to the directory that contains the exported model. param: string $uniqueid The model unique id param: string $modeldir The directory that contains the trained model. |
import(string $uniqueid, string $modeldir, string $importdir) X-Ref |
Imports the provided machine learning model. return: bool Success param: string $uniqueid The model unique id param: string $modeldir The directory that will contain the trained model. param: string $importdir The directory that contains the files to import. |
get_model_filepath(string $modeldir) X-Ref |
Returns the path to the serialised model file in the provided directory. return: string The model file param: string $modeldir The model directory |
extract_metadata($fh) X-Ref |
Extracts metadata from the dataset file. The file poiter should be located at the top of the file. return: array param: resource $fh |
instantiate_algorithm() X-Ref |
Instantiates the ML algorithm. return: \Phpml\Classification\Linear\LogisticRegression |