Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
PHP predictions processor. More...
Public Member Functions | |
classify ($uniqueid, stored_file $dataset, $outputdir) | |
Classifies the provided dataset samples. More... | |
clear_model ($uniqueid, $modelversionoutputdir) | |
Delete the stored models. More... | |
delete_output_dir ($modeloutputdir, $uniqueid) | |
Delete the output directory. More... | |
estimate ($uniqueid, stored_file $dataset, $outputdir) | |
Estimates linear values for the provided dataset samples. More... | |
evaluate_classification ($uniqueid, $maxdeviation, $niterations, stored_file $dataset, $outputdir, $trainedmodeldir) | |
Evaluates this processor classification model using the provided supervised learning dataset. More... | |
evaluate_regression ($uniqueid, $maxdeviation, $niterations, stored_file $dataset, $outputdir, $trainedmodeldir) | |
Evaluates this processor regression model using the provided supervised learning dataset. More... | |
export (string $uniqueid, string $modeldir) | |
Exports the machine learning model. More... | |
import (string $uniqueid, string $modeldir, string $importdir) | |
Imports the provided machine learning model. More... | |
is_ready () | |
Checks if the processor is ready to use. More... | |
train_classification ($uniqueid, stored_file $dataset, $outputdir) | |
Train this processor classification model using the provided supervised learning dataset. More... | |
train_regression ($uniqueid, stored_file $dataset, $outputdir) | |
Train this processor regression model using the provided supervised learning dataset. More... | |
Public Attributes | |
const | BATCH_SIZE = 5000 |
Size of training / prediction batches. | |
const | MODEL_FILENAME = 'model.ser' |
File name of the serialised model. | |
const | TRAIN_ITERATIONS = 500 |
Number of train iterations. | |
Protected Member Functions | |
extract_metadata ($fh) | |
Extracts metadata from the dataset file. More... | |
get_evaluation_result_object (\stored_file $dataset, $scores, $maxdeviation) | |
Returns the results objects from all evaluations. More... | |
get_model_filepath (string $modeldir) | |
Returns the path to the serialised model file in the provided directory. More... | |
instantiate_algorithm () | |
Instantiates the ML algorithm. More... | |
load_classifier ($outputdir) | |
Loads the pre-trained classifier. More... | |
Protected Attributes | |
bool | $limitedsize = false |
PHP predictions processor.
mlbackend_php\processor::classify | ( | $uniqueid, | |
stored_file | $dataset, | ||
$outputdir | |||
) |
Classifies the provided dataset samples.
string | $uniqueid | |
stored_file | $dataset | |
string | $outputdir |
stdClass |
Implements core_analytics\classifier.
mlbackend_php\processor::clear_model | ( | $uniqueid, | |
$modelversionoutputdir | |||
) |
Delete the stored models.
string | $uniqueid | |
string | $modelversionoutputdir |
null |
Implements core_analytics\predictor.
mlbackend_php\processor::delete_output_dir | ( | $modeloutputdir, | |
$uniqueid | |||
) |
Delete the output directory.
string | $modeloutputdir | |
string | $uniqueid |
null |
Implements core_analytics\predictor.
mlbackend_php\processor::estimate | ( | $uniqueid, | |
stored_file | $dataset, | ||
$outputdir | |||
) |
Estimates linear values for the provided dataset samples.
new | coding_exception |
string | $uniqueid | |
stored_file | $dataset | |
mixed | $outputdir |
void |
Implements core_analytics\regressor.
mlbackend_php\processor::evaluate_classification | ( | $uniqueid, | |
$maxdeviation, | |||
$niterations, | |||
stored_file | $dataset, | ||
$outputdir, | |||
$trainedmodeldir | |||
) |
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.
string | $uniqueid | |
float | $maxdeviation | |
int | $niterations | |
stored_file | $dataset | |
string | $outputdir | |
string | $trainedmodeldir |
stdClass |
Implements core_analytics\classifier.
mlbackend_php\processor::evaluate_regression | ( | $uniqueid, | |
$maxdeviation, | |||
$niterations, | |||
stored_file | $dataset, | ||
$outputdir, | |||
$trainedmodeldir | |||
) |
Evaluates this processor regression model using the provided supervised learning dataset.
new | coding_exception |
string | $uniqueid | |
float | $maxdeviation | |
int | $niterations | |
stored_file | $dataset | |
string | $outputdir | |
string | $trainedmodeldir |
stdClass |
Implements core_analytics\regressor.
mlbackend_php\processor::export | ( | string | $uniqueid, |
string | $modeldir | ||
) |
Exports the machine learning model.
moodle_exception |
string | $uniqueid | The model unique id |
string | $modeldir | The directory that contains the trained model. |
string | The path to the directory that contains the exported model. |
Implements core_analytics\packable.
|
protected |
Extracts metadata from the dataset file.
The file poiter should be located at the top of the file.
resource | $fh |
array |
|
protected |
Returns the results objects from all evaluations.
stored_file | $dataset | |
array | $scores | |
float | $maxdeviation |
stdClass |
|
protected |
Returns the path to the serialised model file in the provided directory.
string | $modeldir | The model directory |
string | The model file |
mlbackend_php\processor::import | ( | string | $uniqueid, |
string | $modeldir, | ||
string | $importdir | ||
) |
Imports the provided machine learning model.
string | $uniqueid | The model unique id |
string | $modeldir | The directory that will contain the trained model. |
string | $importdir | The directory that contains the files to import. |
bool | Success |
Implements core_analytics\packable.
|
protected |
Instantiates the ML algorithm.
Phpml |
mlbackend_php\processor::is_ready | ( | ) |
|
protected |
Loads the pre-trained classifier.
moodle_exception |
string | $outputdir |
Phpml |
mlbackend_php\processor::train_classification | ( | $uniqueid, | |
stored_file | $dataset, | ||
$outputdir | |||
) |
Train this processor classification model using the provided supervised learning dataset.
string | $uniqueid | |
stored_file | $dataset | |
string | $outputdir |
stdClass |
Implements core_analytics\classifier.
mlbackend_php\processor::train_regression | ( | $uniqueid, | |
stored_file | $dataset, | ||
$outputdir | |||
) |
Train this processor regression model using the provided supervised learning dataset.
new | coding_exception |
string | $uniqueid | |
stored_file | $dataset | |
string | $outputdir |
stdClass |
Implements core_analytics\regressor.