MySQL HeatWave User Guide
After preparing the data for a regression model, you can train the model.
Review and complete all the tasks to Prepare Data for a Regression Model.
Train the model with the
ML_TRAIN
routine and use the
house_price_training
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.
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='regression_use_case';
The model handle is set to
regression_use_case
.
Run the ML_TRAIN
routine.
mysql> CALL sys.ML_TRAIN('table_name
', 'target_column_name
', JSON_OBJECT('task', 'task_name
'), @variable
);
Replace table_name
,
target_column_name
,
task_name
, and
variable
with your own
values.
The following example runs
ML_TRAIN
on the training
dataset previously created.
mysql> CALL sys.ML_TRAIN('regression_data.house_price_training', 'price', JSON_OBJECT('task', 'regression'), @model);
Where:
regression_data.house_price_training
is the fully qualified name of the table that
contains the training dataset
(database_name.table_name
).
price
is the name of the target
column, which contains ground truth values.
JSON_OBJECT('task', 'regression')
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:
regression_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
@
.
Any valid name for a user-defined variable is
permitted. See
Work with
Model Handles to learn more.
var_name
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 = 'regression_use_case';
+----------+----------------------------------------------+----------------------------------------+
| model_id | model_handle | train_table_name |
+----------+----------------------------------------------+----------------------------------------+
| 2 | regression_use_case | regression_data.house_price_training |
+----------+----------------------------------------------+----------------------------------------+
Learn how to Generate Predictions for a Regression Model.