All Products
Search
Document Center

MaxCompute:ML_PREDICT

Last Updated:Mar 26, 2026

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

ParameterRequiredDescription
model_nameYesThe name of the model. The model's model_type must be BOOSTED_TREE_REGRESSOR or BOOSTED_TREE_CLASSIFIER.
version_nameYesThe model version to use. To use the default version, pass DEFAULT_VERSION.
col1, col2, ...YesThe 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:

FieldTypeApplies toDescription
(result)STRINGBOOSTED_TREE_REGRESSORThe predicted numeric value.
(result)STRUCT<label:STRING, probs:ARRAY(prob:FLOAT)>BOOSTED_TREE_CLASSIFIERA struct containing the predicted class and per-class probabilities.
labelSTRINGBOOSTED_TREE_CLASSIFIERThe predicted class for the row.
probsARRAY(prob:FLOAT)BOOSTED_TREE_CLASSIFIERThe 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.

What's next