ReferenceSQL ReferenceFunctions

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

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.

naiveBayesClassifier

Classifies input text using a Naive Bayes model with ngrams and Laplace smoothing. The model must be configured in RawTree before use.

Syntax

naiveBayesClassifier(model_name, input_text)

Arguments

  • model_name — Name of the pre-configured model. The model must be defined in RawTree's configuration files. String
  • input_text — Text to classify. Input is processed exactly as provided (case/punctuation preserved). String

Returned value

Predicted class ID as an unsigned integer. Class IDs correspond to categories defined during model construction. UInt32

Examples

Classify the language of a text

SELECT naiveBayesClassifier('language', 'How are you?');
┌─naiveBayesClassifier('language', 'How are you?')─┐
          │ 0                                                │
          └──────────────────────────────────────────────────┘

          Result 0 might represent English, while 1 could indicate French - class meanings depend on your training data.

Introduced in version 25.11.