Machine Learning
Machine Learning functions reference.
evalMLMethod
Applies a trained machine learning model to input features to generate predictions.
Syntax
evalMLMethod(model, x1[, x2, ...])Arguments
model— The trained machine learning model.AggregateFunctionStatex1, x2, ...— Feature values for prediction.Float*or(U)Int*
Returned value
Returns the predicted value based on the trained model. Float64
Examples
Example usage
SELECT
evalMLMethod(model, trip_distance),
total_amount
FROM trips
LEFT JOIN models ON year = toYear(pickup_datetime)
LIMIT 5┌─evalMLMethod(model, trip_distance)─┬─total_amount─┐
│ 8.087692004204174 │ 5.4 │
│ 7.861181608305352 │ 4.6 │
│ 26.661544467907536 │ 23.4 │
│ 8.767223191900637 │ 5.8 │
│ 10.80581675499003 │ 9 │
└────────────────────────────────────┴──────────────┘Introduced in version 20.1.0.
naiveBayesClassifier
Classifies input text using a NAIVE_BAYES dictionary. Returns the same predicted class value as dictGet(dictionary_name, class_attribute, input_text), where class_attribute is the name of the class label attribute configured in the dictionary's layout. Unlike dictGet, the result type is always UInt32 rather than the declared type of the class attribute, and input_text must be a String (no key type conversion is applied).
Syntax
naiveBayesClassifier(dictionary_name, input_text)Arguments
dictionary_name— Name of a dictionary with the NAIVE_BAYES layout.Stringinput_text— Text to classify.String
Returned value
Predicted class ID. UInt32
Examples
Classify text
SELECT naiveBayesClassifier('model', 'some text');0Introduced in version 25.11.0.
naiveBayesClassifierWithAllProbs
Classifies input text using a NAIVE_BAYES dictionary and returns all classes with their probabilities, ordered from most to least probable.
Syntax
naiveBayesClassifierWithAllProbs(dictionary_name, input_text)Arguments
dictionary_name— Name of a dictionary with the NAIVE_BAYES layout.Stringinput_text— Text to classify.String
Returned value
Array of (class_id, probability) tuples ordered from most to least probable. Array(Tuple(UInt32, Float64))
Examples
All class probabilities
SELECT naiveBayesClassifierWithAllProbs('model', 'some text');[(0,0.85),(1,0.15)]Introduced in version 26.7.0.
naiveBayesClassifierWithProb
Classifies input text using a NAIVE_BAYES dictionary and returns the predicted class with its probability.
Syntax
naiveBayesClassifierWithProb(dictionary_name, input_text)Arguments
dictionary_name— Name of a dictionary with the NAIVE_BAYES layout.Stringinput_text— Text to classify.String
Returned value
Tuple of (class_id, probability). Tuple(UInt32, Float64)
Examples
Classify with probability
SELECT naiveBayesClassifierWithProb('model', 'some text');(0,0.85)Introduced in version 26.7.0.