The machine learning plugin provides machine learning functionality
as an aggregation function. It enables you to train Support Vector Machine (SVM)
based classifiers and regressors for the supervised learning problems.
The machine learning functions are not optimized for distributed processing.
The capability to train large data sets is limited by this execution of the
final training on a single instance.
To solve a problem with the machine learning technique, especially as a
supervised learning problem, it is necessary to represent the data set
with the sequence of pairs of labels and feature vector. A label is a
target value you want to predict from the unseen feature and a feature is a
A N-dimensional vector whose elements are numerical values. In Trino, a
feature vector is represented as a map-type value, whose key is an index
of each feature, so that it can express a sparse vector.
Since classifiers and regressors can recognize the map-type feature
vector, there is a function to construct the feature from the existing
numerical values, features():
Classification is a type of supervised learning problem to predict the distinct
label from the given feature vector. The interface looks similar to the
construction of the SVM model from the sequence of pairs of labels and features
implemented in Teradata Aster or BigQuery ML.
The function to train a classification model looks like as follows:
classify() returns the predicted label by using the trained model.
The trained model can not be saved natively, and needs to be passed in
the format of a nested query:
Copy
Ask AI
SELECT classify(features(5.9, 3, 5.1, 1.8), model) AS predicted_labelFROM ( SELECT learn_classifier(species, features(sepal_length, sepal_width, petal_length, petal_width)) AS model FROM iris) t
Copy
Ask AI
predicted_label----------------- Iris-virginica
As a result you need to run the training process at the same time when predicting values.
Internally, the model is trained by libsvm.
You can use learn_libsvm_classifier() to control the internal parameters of the model.
Regression is another type of supervised learning problem, predicting continuous
value, unlike the classification problem. The target must be numerical values that can
be described as double.The following code shows the creation of the model predicting sepal_length
from the other 3 features:
Copy
Ask AI
SELECT learn_regressor(sepal_length, features(sepal_width, petal_length, petal_width)) AS modelFROM iris
The way to use the model is similar to the classification case:
Copy
Ask AI
SELECT regress(features(3, 5.1, 1.8), model) AS predicted_targetFROM ( SELECT learn_regressor(sepal_length, features(sepal_width, petal_length, petal_width)) AS model FROM iris) t;