After generating predictions, you can score the model to assess its reliability. For a list of scoring metrics you can use with forecasting models, see Forecasting Metrics. For this use case, you use the test dataset for validation. In a real-world use case, you should use a separate validation dataset that has the target column and ground truth values for the scoring validation. You should also use a larger number of records for training and validation to get a valid score.
The
ML_SCORE
routine does not require a
target_column_name
for forecasting, so you
can set it to NULL
. However, the target
column needs to be in the table to generate a valid score
value.
Complete the following tasks:
-
If not already done, load the model. You can use the session variable for the model that is valid for the duration of the connection. Alternatively, you can use the model handle previously set. For the option to set the user name, you can set it to
NULL
.The following example uses the session variable.
mysql> CALL sys.ML_MODEL_LOAD(@model, NULL);
The following example uses the model handle.
mysql> CALL sys.ML_MODEL_LOAD('forecasting_use_case', NULL);
-
Score the model with the
ML_SCORE
routine and use theneg_sym_mean_abs_percent_error
metric.mysql> CALL sys.ML_SCORE(table_name, target_column_name, model_handle, metric, score, [options]);
Replace
table_name
,target_column_name
,model_handle
,metric
,score
with your own values.The following example runs
ML_SCORE
on the testing dataset previously created.mysql> CALL sys.ML_SCORE('forecasting_data.electricity_demand_test', 'demand', @model, 'neg_sym_mean_abs_percent_error', @forecasting_score, NULL);
Where:
forecasting_data.electricity_demand_test
is the fully qualified name of the validation dataset.demand
is the target column name with ground truth values.@model
is the session variable for the model handle.neg_sym_mean_abs_percent_error
is the selected scoring metric.@forecasting_score
is the session variable name for the score value.NULL
means that no other options are defined for the routine.
-
Retrieve the score by querying the @forecasting_score session variable.
mysql> SELECT @forecasting_score; +----------------------+ | @forecasting_score | +----------------------+ | -0.06810028851032257 | +----------------------+
-
If done working with the model, unload it with the
ML_MODEL_UNLOAD
routine.mysql> CALL sys.ML_MODEL_UNLOAD('forecasting_use_case');
To avoid consuming too much memory, it is good practice to unload a model when you are finished using it.
Review other Machine Learning Use Cases.