Documentation Home
MySQL 9.2 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 259.6Kb
Man Pages (Zip) - 366.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


27.3.9.2 Classifier Class

This class encapsulates the classification task as described in Training a Model. Classifier supports methods for loading, training, and unloading models, predicting labels, calculating probabilities, producing explainers, and related tasks.

An instance of Classifier has three accessible properties, listed here:

  • name (String): The model name.

  • metadata (Object): Model metadata stored in the model catalog. See Model Metadata.

  • trainOptions (Object): The training options specified in the constructor.

Classifier Constructor

You can obtain an instance of Classifier by invoking its constructor, shown here:

Signature

  • Press CTRL+C to copy
    new ml.Classifier( String name[, Object trainOptions] )

Arguments

  • name (String): Unique identifier for this Classifier.

  • trainOptions (Object) (optional): Training options; these are the same as the training options used with sys.ML_TRAIN.

Return type

  • An instance of Classifier.

It is also possible to obtain a Classifier by invoking ml.load(). See ml.load(), for more information.

Classifier was added in MySQL 9.2.0.

Classifier.train()

Trains and loads a new classifier. This method acts as a wrapper for both sys.ML_TRAIN and sys.ML_MODEL_LOAD, but is specific to the HeatWave AutoML classification task.

Signature

  • Press CTRL+C to copy
    Classifier.train( Table trainData, String targetColumnName )

Arguments

  • trainData (Table): A Table containing a training dataset. The table must not take up more than 10 GB space, or hold more than 100 million rows or more than 1017 columns.

  • targetColumnName (String): Name of the target column containing ground truth values. The type used for this column cannot be TEXT.

Return type

  • None.

Classifier.fit()

An alias for train(), and identical to it in all respects save the method name. See Classifier.train(), for more information.

Classifier.predict()

This method predicts labels; it has two variants, one of which predicts labels from data found in the indicated table and stores them in an output table; this is a wrapper for sys.ML_PREDICT_TABLE. The other variant of this method acts as a wrapper for sys.ML_PREDICT_ROW, and predicts a label for a single set of sample data and returns it to the caller. Both versions of predict() are shown here.

Version 1

Predicts labels and saves them in the specified output table.

Signature

  • Press CTRL+C to copy
    Classifier.predict( Table testData, Table outputTable[, Object options] )

Arguments

  • testData (Table): Table containing test data.

  • outputTable (Table): Table in which to store labels. The content and format of the output is the same as that generated by ML_PREDICT_TABLE.

  • options (Object) (optional): Set of options in JSON format. See ML_PREDICT_TABLE, for more information.

Return type

Version 2

Predicts a label for a single sample of data, and returns it. See ML_PREDICT_ROW, for more information.

Signature

  • Press CTRL+C to copy
    String Classifier.predict( Object sample )

Arguments

  • sample (Object): Sample data. This argument must contain members that were used for training; extra members may be included, but these are ignored during prediction.

Return type

  • String. See the documentation for ML_PREDICT_ROW for more information.

Classifier.predictProba()

Obtains the probabilities for all classes of the passed sample data. Like the single-argument version of predict(), this method is a wrapper for sys.ML_PREDICT_ROW, but unlike predict(), predictProba() returns the probabilities only.

Signature

  • Press CTRL+C to copy
    Classifier.predict( Object sample )

Arguments

  • sample (Object): Sample data, in the form of a JSON object. As with the single-argument version of Classifier.predict(), this argument must contain members that were used for training; extra members may be included, but these are ignored during prediction.

Return type

  • Object. The probabilities for the sample data, in JSON format.

Classifier.score()

Returns the score for the test data in the indicated table and column. For possible metric values and their effects, see Optimization and Scoring Metrics.

This method serves as a JavaScript wrapper for sys.ML_SCORE.

Signature

  • Press CTRL+C to copy
    score( Table testData, String targetColumnName, String metric[, Object options] )

Arguments

  • testData (Table): Table containing test data to be scored; this table must contain the same columns as the training dataset.

  • targetColumnName (String): Name of the target column containing ground truth values.

  • metric (String): Name of the scoring metric. See Optimization and Scoring Metrics, for information about the metrics compatible with AutoML classification.

  • options (Object) (optional): A set of options in JSON format. See the description of ML_SCORE for more information.

Return type

  • Number.

Classifier.explain()

Given a Table containing a labeled, trained dataset and the name of a table column containing ground truth values, this method returns the newly trained explainer.

This method serves as a wrapper for the HeatWave AutoML sys.ML_EXPLAIN routine; see the description of that routine for further information.

Signature

  • Press CTRL+C to copy
    explain( Table data, String targetColumnName[, Object options] )

Arguments

  • data (Table): A table containing trained data.

  • targetColumnName (String): The name of the column containing ground truth values.

  • options (Object) (optional): A set of optional parameters, in JSON format.

Return type

  • None. Adds a model explainer to the model catalog; see ML_EXPLAIN, for more information.

Classifier.getExplainer()

Returns an explainer for this classifier, if one exists.

Signature

  • Press CTRL+C to copy
    Object Classifier.getExplainer()

Arguments

  • None.

Return type

  • Object

Classifier.unload()

Unloads the model. This method is a wrapper for sys.ML_MODEL_UNLOAD.

Signature

  • Press CTRL+C to copy
    Classifier.unload()

Arguments

  • None.

Return type

  • undefined