# Machine Learning (/docs/reference/sql/functions/machine-learning)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

evalMLMethod [#evalmlmethod]

Applies a trained machine learning model to input features to generate predictions.

**Syntax**

```sql
evalMLMethod(model, x1[, x2, ...])
```

**Arguments**

* `model` — The trained machine learning model. [`AggregateFunctionState`](/reference/data-types/aggregatefunction)
* `x1, x2, ...` — Feature values for prediction. [`Float*`](/reference/data-types/float) or [`(U)Int*`](/reference/data-types/int-uint)

**Returned value**

Returns the predicted value based on the trained model. [`Float64`](/reference/data-types/float)

**Examples**

**Example usage**

```sql title=Query
SELECT
evalMLMethod(model, trip_distance),
total_amount
FROM trips
LEFT JOIN models ON year = toYear(pickup_datetime)
LIMIT 5
```

```text title=Response
┌─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 [#naivebayesclassifier]

Classifies input text using a [`NAIVE_BAYES`](/reference/statements/create/dictionary/layouts/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](/reference/statements/create/dictionary/layouts/naive-bayes#layout-parameters). 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**

```sql
naiveBayesClassifier(dictionary_name, input_text)
```

**Arguments**

* `dictionary_name` — Name of a dictionary with the NAIVE\_BAYES layout. [`String`](/reference/data-types/string)
* `input_text` — Text to classify. [`String`](/reference/data-types/string)

**Returned value**

Predicted class ID. [`UInt32`](/reference/data-types/int-uint)

**Examples**

**Classify text**

```sql title=Query
SELECT naiveBayesClassifier('model', 'some text');
```

```text title=Response
0
```

*Introduced in version 25.11.0.*

naiveBayesClassifierWithAllProbs [#naivebayesclassifierwithallprobs]

Classifies input text using a [`NAIVE_BAYES`](/reference/statements/create/dictionary/layouts/naive-bayes) dictionary and returns all classes with their probabilities, ordered from most to least probable.

**Syntax**

```sql
naiveBayesClassifierWithAllProbs(dictionary_name, input_text)
```

**Arguments**

* `dictionary_name` — Name of a dictionary with the NAIVE\_BAYES layout. [`String`](/reference/data-types/string)
* `input_text` — Text to classify. [`String`](/reference/data-types/string)

**Returned value**

Array of (class\_id, probability) tuples ordered from most to least probable. [`Array(Tuple(UInt32, Float64))`](/reference/data-types/array)

**Examples**

**All class probabilities**

```sql title=Query
SELECT naiveBayesClassifierWithAllProbs('model', 'some text');
```

```text title=Response
[(0,0.85),(1,0.15)]
```

*Introduced in version 26.7.0.*

naiveBayesClassifierWithProb [#naivebayesclassifierwithprob]

Classifies input text using a [`NAIVE_BAYES`](/reference/statements/create/dictionary/layouts/naive-bayes) dictionary and returns the predicted class with its probability.

**Syntax**

```sql
naiveBayesClassifierWithProb(dictionary_name, input_text)
```

**Arguments**

* `dictionary_name` — Name of a dictionary with the NAIVE\_BAYES layout. [`String`](/reference/data-types/string)
* `input_text` — Text to classify. [`String`](/reference/data-types/string)

**Returned value**

Tuple of (class\_id, probability). [`Tuple(UInt32, Float64)`](/reference/data-types/tuple)

**Examples**

**Classify with probability**

```sql title=Query
SELECT naiveBayesClassifierWithProb('model', 'some text');
```

```text title=Response
(0,0.85)
```

*Introduced in version 26.7.0.*
