Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

Defines 1 class


Class: processor  - X-Ref

PHP predictions processor.

is_ready()   X-Ref
Checks if the processor is ready to use.

return: bool

clear_model($uniqueid, $modelversionoutputdir)   X-Ref
Delete the stored models.

param: string $uniqueid
param: string $modelversionoutputdir
return: null

delete_output_dir($modeloutputdir, $uniqueid)   X-Ref
Delete the output directory.

param: string $modeloutputdir
param: string $uniqueid
return: null

train_classification($uniqueid, \stored_file $dataset, $outputdir)   X-Ref
Train this processor classification model using the provided supervised learning dataset.

param: string $uniqueid
param: \stored_file $dataset
param: string $outputdir
return: \stdClass

classify($uniqueid, \stored_file $dataset, $outputdir)   X-Ref
Classifies the provided dataset samples.

param: string $uniqueid
param: \stored_file $dataset
param: string $outputdir
return: \stdClass

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.

param: string $uniqueid
param: float $maxdeviation
param: int $niterations
param: \stored_file $dataset
param: string $outputdir
param: string $trainedmodeldir
return: \stdClass

get_evaluation_result_object(\stored_file $dataset, $scores, $maxdeviation)   X-Ref
Returns the results objects from all evaluations.

param: \stored_file $dataset
param: array $scores
param: float $maxdeviation
return: \stdClass

load_classifier($outputdir)   X-Ref
Loads the pre-trained classifier.

param: string $outputdir
return: \Phpml\Classification\Linear\LogisticRegression

train_regression($uniqueid, \stored_file $dataset, $outputdir)   X-Ref
Train this processor regression model using the provided supervised learning dataset.

param: string $uniqueid
param: \stored_file $dataset
param: string $outputdir
return: \stdClass

estimate($uniqueid, \stored_file $dataset, $outputdir)   X-Ref
Estimates linear values for the provided dataset samples.

param: string $uniqueid
param: \stored_file $dataset
param: mixed $outputdir
return: void

evaluate_regression($uniqueid, $maxdeviation, $niterations, \stored_file $dataset,$outputdir, $trainedmodeldir)   X-Ref
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
param: string $trainedmodeldir
return: \stdClass

export(string $uniqueid, string $modeldir)   X-Ref
Exports the machine learning model.

param: string $uniqueid  The model unique id
param: string $modeldir  The directory that contains the trained model.
return: string            The path to the directory that contains the exported model.

import(string $uniqueid, string $modeldir, string $importdir)   X-Ref
Imports the provided machine learning model.

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.
return: bool Success

get_model_filepath(string $modeldir)   X-Ref
Returns the path to the serialised model file in the provided directory.

param: string $modeldir The model directory
return: string           The model file

extract_metadata($fh)   X-Ref
Extracts metadata from the dataset file.

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

param: resource $fh
return: array

instantiate_algorithm()   X-Ref
Instantiates the ML algorithm.

return: \Phpml\Classification\Linear\LogisticRegression