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

Python predictions processor. More...

Inheritance diagram for mlbackend_python\processor:

Public Member Functions

 __construct ()
 The constructor.
 
 classify ($uniqueid, stored_file $dataset, $outputdir)
 Classifies the provided dataset samples.
 
 clear_model ($uniqueid, $modelversionoutputdir)
 Delete the model version output directory.
 
 delete_output_dir ($modeloutputdir, $uniqueid)
 Delete the model 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 ()
 Is the plugin ready to be used?.
 
 train_classification ($uniqueid, stored_file $dataset, $outputdir)
 Trains a machine learning algorithm with the provided dataset.
 
 train_regression ($uniqueid, stored_file $dataset, $outputdir)
 Train this processor regression model using the provided supervised learning dataset.
 

Static Public Member Functions

static check_pip_package_version ($actual, $required=self::REQUIRED_PIP_PACKAGE_VERSION)
 Check that the given package version can be used and return the error status.
 

Public Attributes

const REQUIRED_PIP_PACKAGE_VERSION = '3.0.5'
 The required version of the python package that performs all calculations.
 

Protected Member Functions

 add_extra_result_info (\stdClass $resultobj)
 Adds extra information to results info.
 
 exec_command (string $modulename, array $params, string $errorlangstr)
 Executes the specified module.
 
 get_file_path (\stored_file $file)
 Returns the path to the dataset file.
 
 is_python_server_ready ()
 Checks if the server can be accessed.
 
 is_webserver_ready ()
 Checks if the python package is available in the web server executing this script.
 
 server_request ($url, string $method, array $requestparams, ?array $options=null)
 Sends a request to the python ML server.
 

Protected Attributes

string $host
 Remote server host.
 
string $password
 Server password for $this->username.
 
string $pathtopython
 The path to the Python bin.
 
int $port
 Remote server port.
 
bool $secure
 Whether to use http or https.
 
string $username
 Server username.
 
bool $useserver
 The python package is installed in a server.
 

Detailed Description

Python predictions processor.

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

Member Function Documentation

◆ add_extra_result_info()

mlbackend_python\processor::add_extra_result_info ( \stdClass $resultobj)
protected

Adds extra information to results info.

Parameters
stdClass$resultobj
Return values
stdClass

◆ check_pip_package_version()

static mlbackend_python\processor::check_pip_package_version ( $actual,
$required = self::REQUIRED_PIP_PACKAGE_VERSION )
static

Check that the given package version can be used and return the error status.

When evaluating the version, we assume the sematic versioning scheme as described at https://semver.org/.

Parameters
string$actualThe actual Python package version
string$requiredThe required version of the package
Return values
int-1 = actual version is too low, 1 = actual version too high, 0 = actual version is ok

◆ classify()

mlbackend_python\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_python\processor::clear_model ( $uniqueid,
$modelversionoutputdir )

Delete the model version output directory.

Exceptions
moodle_exception
Parameters
string$uniqueid
string$modelversionoutputdir
Return values
null

Implements core_analytics\predictor.

◆ delete_output_dir()

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

Delete the model output directory.

Exceptions
moodle_exception
Parameters
string$modeloutputdir
string$uniqueid
Return values
null

Implements core_analytics\predictor.

◆ estimate()

mlbackend_python\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_python\processor::evaluate_classification ( $uniqueid,
$maxdeviation,
$niterations,
stored_file $dataset,
$outputdir,
$trainedmodeldir )

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

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

Implements core_analytics\classifier.

◆ evaluate_regression()

mlbackend_python\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.

◆ exec_command()

mlbackend_python\processor::exec_command ( string $modulename,
array $params,
string $errorlangstr )
protected

Executes the specified module.

Parameters
string$modulename
array$params
string$errorlangstr
Return values
array[0] is the result body and [1] the exit code.

◆ export()

mlbackend_python\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.

◆ get_file_path()

mlbackend_python\processor::get_file_path ( \stored_file $file)
protected

Returns the path to the dataset file.

Parameters
stored_file$file
Return values
string

◆ import()

mlbackend_python\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.

◆ is_python_server_ready()

mlbackend_python\processor::is_python_server_ready ( )
protected

Checks if the server can be accessed.

Return values
bool|stringTrue or an error string.

◆ is_ready()

mlbackend_python\processor::is_ready ( )

Is the plugin ready to be used?.

Return values
bool|stringReturns true on success, a string detailing the error otherwise

Implements core_analytics\predictor.

◆ is_webserver_ready()

mlbackend_python\processor::is_webserver_ready ( )
protected

Checks if the python package is available in the web server executing this script.

Return values
bool|stringReturns true on success, a string detailing the error otherwise

◆ server_request()

mlbackend_python\processor::server_request ( $url,
string $method,
array $requestparams,
?array $options = null )
protected

Sends a request to the python ML server.

Parameters
moodle_url$urlThe requested url in the python ML server
string$methodThe curl method to use
array$requestparamsCurl request params
array | null$optionsCurl request options
Return values
array[0] for the response body and [1] for the http code

◆ train_classification()

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

Trains a machine learning algorithm with the provided dataset.

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

Implements core_analytics\classifier.

◆ train_regression()

mlbackend_python\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: