MySQL HeatWave User Guide

6.7.1.2 Train a Classification Model

After preparing the data for a classification model, you can train the model.

Before You Begin
Train Model

Train the model with the ML_TRAIN routine and use the training_data table previously created. Before training the model, it is good practice to define the model handle instead of automatically creating one. See Define Model Handle.

  1. Optionally, set the value of the session variable, which sets the model handle to this same value.

    mysql> SET @variable = 'model_handle';
    

    Replace @variable and model_handle with your own definitions. For example:

    mysql> SET @model='classification_use_case';
    

    The model handle is set to classification_use_case.

  2. Run the ML_TRAIN routine.

    mysql> CALL sys.ML_TRAIN('table_name', 'target_column_name', JSON_OBJECT('task', 'task_name'), model_handle);
    

    Replace table_name, target_column_name, task_name, and model_handle with your own values.

    The following example runs ML_TRAIN on the training dataset previously created.

    mysql> CALL sys.ML_TRAIN('classification_data.Loan_Training', 'Approved', JSON_OBJECT('task', 'classification'), @model);
    

    Where:

    • classification_data.Loan_Training is the fully qualified name of the table that contains the training dataset (database_name.table_name).

    • Approved is the name of the target column, which contains ground truth values.

    • JSON_OBJECT('task', 'classification') specifies the machine learning task type.

    • @model is the session variable previously set that defines the model handle to the name defined by the user: classification_use_case. If you do not define the model handle before training the model, the model handle is automatically generated, and the session variable only stores the model handle for the duration of the connection. User variables are written as @var_name. Any valid name for a user-defined variable is permitted. See Work with Model Handles to learn more.

  3. When the training operation finishes, the model handle is assigned to the @model session variable, and the model is stored in the model catalog. View the entry in the model catalog with the following query. Replace user1 with your MySQL account name.

    mysql> SELECT model_id, model_handle, train_table_name FROM ML_SCHEMA_user1.MODEL_CATALOG WHERE model_handle = 'classification_use_case';
    +----------+----------------------------------------------+-------------------------------------+
    | model_id | model_handle                                 | train_table_name                    |
    +----------+----------------------------------------------+-------------------------------------+
    |        1 | classification_use_case                      | classification_data.Loan_Training   |
    +----------+----------------------------------------------+-------------------------------------+
    
What's Next