ML_PREDICT runs inference on structured data using a pre-trained boosted tree model. Use it for classification and regression tasks directly in MaxCompute SQL.
Syntax
STRING|STRUCT ML_PREDICT(<model_name>, <version_name>, col1, col2, ...);Parameters
| Parameter | Required | Description |
|---|---|---|
model_name | Yes | The name of the model. The model's model_type must be BOOSTED_TREE_REGRESSOR or BOOSTED_TREE_CLASSIFIER. |
version_name | Yes | The model version to use. To use the default version, pass DEFAULT_VERSION. |
col1, col2, ... | Yes | The input columns for prediction. The column type, order, and count must match the model definition. An error is returned if they do not match. |
Return value
The return type depends on model_type:
| Field | Type | Applies to | Description |
|---|---|---|---|
| (result) | STRING | BOOSTED_TREE_REGRESSOR | The predicted numeric value. |
| (result) | STRUCT<label:STRING, probs:ARRAY(prob:FLOAT)> | BOOSTED_TREE_CLASSIFIER | A struct containing the predicted class and per-class probabilities. |
label | STRING | BOOSTED_TREE_CLASSIFIER | The predicted class for the row. |
probs | ARRAY(prob:FLOAT) | BOOSTED_TREE_CLASSIFIER | The predicted probabilities for each class. |
Examples
Regression model
Call the XGBoost regression model demo_model_xgboost_regressor at version v01. If this model does not exist, create it first. For details, see Train and predict with an XGBoost model in MaxCompute.
SELECT ML_PREDICT(demo_model_xgboost_regressor, v01, 0.22438f, 0f, 9.69f, 0, 0.585f, 6.027f, 79.7f, 2.4982f, 6.123f, 391f, 19.2f, 14.33f);Result:
+----------+
| _c0 |
+----------+
| 20.03961 |
+----------+Classification model
Call the XGBoost classification model test_xgboost_classifier at version v1. If this model does not exist, create it first. For details, see Create and delete a model.
SELECT ML_PREDICT(test_xgboost_classifier, v1, 1, 2, 3, 4);Result:
+---------------------------------------------------------------------+
| _c0 |
+---------------------------------------------------------------------+
| {label:0, probs:[0.9266666, 0.03781649, 0.03551693]} |
+---------------------------------------------------------------------+The label field contains the predicted class. The probs array contains the predicted probabilities for each class.