After training the model, you can generate predictions.
To generate predictions, use the sample data from the
house_price_testing
dataset. Even though
the table has labels for the price
target
column, the column is not considered when generating
predictions. This allows you to compare the predictions to the
actual values in the dataset and determine if the predictions
are reliable. Once you determine the trained model is reliable
for generating predictions, you can start using unlabeled
datasets for generating predictions.
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('regression_use_case', NULL);
-
Make predictions for the test dataset by using the
ML_PREDICT_TABLE
routine.mysql> CALL sys.ML_PREDICT_TABLE(table_name, model_handle, output_table_name), [options]);
Replace
table_name
,model_handle
, andoutput_table_name
with your own values. Addoptions
as needed.The following example runs
ML_PREDICT_TABLE
on the testing dataset previously created.mysql> CALL sys.ML_PREDICT_TABLE('regression_data.house_price_testing', @model, 'regression_data.house_price_predictions', NULL);
Where:
regression_data.house_price_testing
is the fully qualified name of the input table that contains the data to generate predictions for (database_name.table_name
).@model
is the session variable for the model handle.regression_data.house_price_predictions
is the fully qualified name of the output table with predictions (database_name.table_name
).NULL
sets no options for the routine.
-
Query the
price
,Prediction
, andml_results
columns from the output table. This allows you to compare the real value with the generated prediction. If needed, you can also query all the columns from the table (SELECT * FROM house_price_predictions
) to review all the data at once.mysql> SELECT price, Prediction, ml_results FROM house_price_predictions; +--------+------------+------------------------------------------+ | price | Prediction | ml_results | +--------+------------+------------------------------------------+ | 470000 | 534372 | {"predictions": {"price": 534371.5625}} | | 630000 | 669040 | {"predictions": {"price": 669040.125}} | | 530000 | 512676 | {"predictions": {"price": 512676.40625}} | | 780000 | 794059 | {"predictions": {"price": 794059.0}} | | 460000 | 489206 | {"predictions": {"price": 489206.0}} | | 510000 | 534240 | {"predictions": {"price": 534239.8125}} | | 500000 | 532544 | {"predictions": {"price": 532543.9375}} | | 600000 | 698540 | {"predictions": {"price": 698539.9375}} | | 430000 | 454276 | {"predictions": {"price": 454275.5}} | | 760000 | 794059 | {"predictions": {"price": 794059.0}} | +--------+------------+------------------------------------------+ 10 rows in set (0.0417 sec)
Review the predictions and compare with the real prices.
To learn more about generating predictions for one or more rows of data, see Generate Predictions for a Row of Data.