Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
mlbackend_php\processor Class Reference

PHP predictions processor. More...

Inheritance diagram for mlbackend_php\processor:

Public Member Functions

 classify ($uniqueid, stored_file $dataset, $outputdir)
 Classifies the provided dataset samples.
 
 clear_model ($uniqueid, $modelversionoutputdir)
 Delete the stored models.
 
 delete_output_dir ($modeloutputdir, $uniqueid)
 Delete the output directory.
 
 estimate ($uniqueid, stored_file $dataset, $outputdir)
 Estimates linear values for the provided dataset samples.
 
 evaluate_classification ($uniqueid, $maxdeviation, $niterations, stored_file $dataset, $outputdir, $trainedmodeldir)
 Evaluates this processor classification model using the provided supervised learning dataset.
 
 evaluate_regression ($uniqueid, $maxdeviation, $niterations, stored_file $dataset, $outputdir, $trainedmodeldir)
 Evaluates this processor regression model using the provided supervised learning dataset.
 
 export (string $uniqueid, string $modeldir)
 Exports the machine learning model.
 
 import (string $uniqueid, string $modeldir, string $importdir)
 Imports the provided machine learning model.
 
 is_ready ()
 Checks if the processor is ready to use.
 
 train_classification ($uniqueid, stored_file $dataset, $outputdir)
 Train this processor classification model using the provided supervised learning dataset.
 
 train_regression ($uniqueid, stored_file $dataset, $outputdir)
 Train this processor regression model using the provided supervised learning dataset.
 

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.
 
 get_evaluation_result_object (\stored_file $dataset, $scores, $maxdeviation)
 Returns the results objects from all evaluations.
 
 get_model_filepath (string $modeldir)
 Returns the path to the serialised model file in the provided directory.
 
 instantiate_algorithm ()
 Instantiates the ML algorithm.
 
 load_classifier ($outputdir)
 Loads the pre-trained classifier.
 

Protected Attributes

bool $limitedsize = false
 

Detailed Description

PHP predictions processor.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ classify()

mlbackend_php\processor::classify ( $uniqueid,
stored_file $dataset,
$outputdir )

Classifies the provided dataset samples.

Parameters
string$uniqueid
stored_file$dataset
string$outputdir
Return values
stdClass

Implements core_analytics\classifier.

◆ clear_model()

mlbackend_php\processor::clear_model ( $uniqueid,
$modelversionoutputdir )

Delete the stored models.

Parameters
string$uniqueid
string$modelversionoutputdir
Return values
null

Implements core_analytics\predictor.

◆ delete_output_dir()

mlbackend_php\processor::delete_output_dir ( $modeloutputdir,
$uniqueid )

Delete the output directory.

Parameters
string$modeloutputdir
string$uniqueid
Return values
null

Implements core_analytics\predictor.

◆ estimate()

mlbackend_php\processor::estimate ( $uniqueid,
stored_file $dataset,
$outputdir )

Estimates linear values for the provided dataset samples.

Exceptions
newcoding_exception
Parameters
string$uniqueid
stored_file$dataset
mixed$outputdir
Return values
void

Implements core_analytics\regressor.

◆ evaluate_classification()

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.

Parameters
string$uniqueid
float$maxdeviation
int$niterations
stored_file$dataset
string$outputdir
string$trainedmodeldir
Return values
stdClass

Implements core_analytics\classifier.

◆ evaluate_regression()

mlbackend_php\processor::evaluate_regression ( $uniqueid,
$maxdeviation,
$niterations,
stored_file $dataset,
$outputdir,
$trainedmodeldir )

Evaluates this processor regression model using the provided supervised learning dataset.

Exceptions
newcoding_exception
Parameters
string$uniqueid
float$maxdeviation
int$niterations
stored_file$dataset
string$outputdir
string$trainedmodeldir
Return values
stdClass

Implements core_analytics\regressor.

◆ export()

mlbackend_php\processor::export ( string $uniqueid,
string $modeldir )

Exports the machine learning model.

Exceptions
moodle_exception
Parameters
string$uniqueidThe model unique id
string$modeldirThe directory that contains the trained model.
Return values
stringThe path to the directory that contains the exported model.

Implements core_analytics\packable.

◆ extract_metadata()

mlbackend_php\processor::extract_metadata ( $fh)
protected

Extracts metadata from the dataset file.

The file poiter should be located at the top of the file.

Parameters
resource$fh
Return values
array

◆ get_evaluation_result_object()

mlbackend_php\processor::get_evaluation_result_object ( \stored_file $dataset,
$scores,
$maxdeviation )
protected

Returns the results objects from all evaluations.

Parameters
stored_file$dataset
array$scores
float$maxdeviation
Return values
stdClass

◆ get_model_filepath()

mlbackend_php\processor::get_model_filepath ( string $modeldir)
protected

Returns the path to the serialised model file in the provided directory.

Parameters
string$modeldirThe model directory
Return values
stringThe model file

◆ import()

mlbackend_php\processor::import ( string $uniqueid,
string $modeldir,
string $importdir )

Imports the provided machine learning model.

Parameters
string$uniqueidThe model unique id
string$modeldirThe directory that will contain the trained model.
string$importdirThe directory that contains the files to import.
Return values
boolSuccess

Implements core_analytics\packable.

◆ instantiate_algorithm()

mlbackend_php\processor::instantiate_algorithm ( )
protected

Instantiates the ML algorithm.

Return values
Phpml\Classification\Linear\LogisticRegression

◆ is_ready()

mlbackend_php\processor::is_ready ( )

Checks if the processor is ready to use.

Return values
bool

Implements core_analytics\predictor.

◆ load_classifier()

mlbackend_php\processor::load_classifier ( $outputdir)
protected

Loads the pre-trained classifier.

Exceptions
moodle_exception
Parameters
string$outputdir
Return values
Phpml\Classification\Linear\LogisticRegression

◆ train_classification()

mlbackend_php\processor::train_classification ( $uniqueid,
stored_file $dataset,
$outputdir )

Train this processor classification model using the provided supervised learning dataset.

Parameters
string$uniqueid
stored_file$dataset
string$outputdir
Return values
stdClass

Implements core_analytics\classifier.

◆ train_regression()

mlbackend_php\processor::train_regression ( $uniqueid,
stored_file $dataset,
$outputdir )

Train this processor regression model using the provided supervised learning dataset.

Exceptions
newcoding_exception
Parameters
string$uniqueid
stored_file$dataset
string$outputdir
Return values
stdClass

Implements core_analytics\regressor.


The documentation for this class was generated from the following file: