Overview

更新时间:
复制 MD 格式

SQL for Machine Learning (SQLML) is a MaxCompute feature that provides a SQL interface for machine learning. SQLML uses Platform for AI to perform operations such as model creation, prediction, and evaluation. This topic describes the features of SQLML, the supported machine learning models, and its prediction and evaluation functions.

Features

The MaxCompute SQLML feature requires both MaxCompute and PAI. You can use a client to develop SQLML jobs. These jobs use Platform for AI to train models on data in MaxCompute and make predictions to guide your business planning. The components work as follows:

MaxCompute SQLML allows data engineers, analysts, and data scientists to use SQL to create, train, and apply machine learning models. SQL practitioners can use their existing skills to apply machine learning without migrating data.

Instructions

Follow these steps to use the MaxCompute SQLML feature:

  1. Activate MaxCompute, DataWorks (Basic Edition), and Platform for AI services (pay-as-you-go for PAI-Studio, PAI-DSW, and PAI-EAS).

  2. Dataset preparation

    This data is used for model training and prediction.

  3. Create or configure a DataWorks workspace. Set the computing engine service to MaxCompute and the machine learning service to PAI Studio.

  4. Use DataWorks to create a table for the dataset and import the data.

  5. Process the imported data based on the model's requirements. Then, create a training dataset and a test dataset. The training dataset is used for model training, and the test dataset is used for prediction.

  6. Create a machine learning model and make predictions using the prediction model function provided by MaxCompute.

  7. Evaluate the accuracy of the prediction results using the evaluation model function provided by MaxCompute.

For a quick start example, see Quick Start.

Supported machine learning models

MaxCompute SQLML currently supports the following machine learning models:

Supported prediction model function

MaxCompute SQLML currently supports the ml_predict prediction model function. The syntax is as follows:

ml_predict(model <model_name>, table <data_source>[, map<string, string> <parameters>])

Supported evaluation model functions

MaxCompute SQLML currently supports the following evaluation model functions to assess the accuracy of prediction results:

  • Binary classification evaluation: This evaluation is performed by the built-in function ml_evaluate. It supports the calculation of metrics such as AUC, KS, and F1 score. The syntax is as follows:

    ml_evaluate(table <data_source>[, map<string, string> <parameters>])
  • Multiclass classification evaluation: This evaluation is performed by the built-in function ml_multiclass_evaluate. It evaluates the performance of a multiclass classification model based on the predicted and original results. The supported metrics include accuracy, kappa, and F1-score. The syntax is as follows:

    ml_multiclass_evaluate(table <data_source>[, map<string, string> <parameters>])
  • Linear regression evaluation: This evaluation is performed by the built-in function ml_regression_evaluate. It evaluates the performance of a regression algorithm model based on the predicted and original results. The output includes metrics and a histogram of residuals. The metrics include SST, SSE, SSR, R-squared, R, MSE, RMSE, MAE, MAD, MAPE, count, yMean, and predictMean. The syntax is as follows:

    ml_regression_evaluate(table <data_source>[, map<string, string> <parameters>])

In the preceding syntax: