ClickHouse/docs/en/sql-reference/functions/machine-learning-functions.md
2021-03-16 13:30:05 +03:00

3.3 KiB

toc_priority toc_title
64 Machine Learning

Machine Learning Functions

evalMLMethod

Prediction using fitted regression models uses evalMLMethod function. See link in linearRegression.

stochasticLinearRegression

The stochasticLinearRegression aggregate function implements stochastic gradient descent method using linear model and MSE loss function. Uses evalMLMethod to predict on new data.

stochasticLogisticRegression

The stochasticLogisticRegression aggregate function implements stochastic gradient descent method for binary classification problem. Uses evalMLMethod to predict on new data.

bayesAB

Compares test groups (variants) and calculates for each group the probability to be the best one. The first group is used as a control group.

Syntax

bayesAB(distribution_name, higher_is_better, variant_names, x, y)

Arguments

  • distribution_name — Name of the probability distribution. String. Possible values:

  • higher_is_better — Boolean flag. Boolean. Possible values:

    • 0 — lower values are considered to be better than higher
    • 1 — higher values are considered to be better than lower
  • variant_names — Variant names. Array(String).

  • x — Numbers of tests for the corresponding variants. Array(Float64).

  • y — Numbers of successful tests for the corresponding variants. Array(Float64).

!!! note "Note" All three arrays must have the same size. All x and y values must be non-negative constant numbers. y cannot be larger than x.

Returned values

For each variant the function calculates:

  • beats_control — long-term probability to out-perform the first (control) variant
  • to_be_best — long-term probability to out-perform all other variants

Type: JSON.

Example

Query:

SELECT bayesAB('beta', 1, ['Control', 'A', 'B'], [3000., 3000., 3000.], [100., 90., 110.]) FORMAT PrettySpace;

Result:

{
   "data":[
      {
         "variant_name":"Control",
         "x":3000,
         "y":100,
         "beats_control":0,
         "to_be_best":0.22619
      },
      {
         "variant_name":"A",
         "x":3000,
         "y":90,
         "beats_control":0.23469,
         "to_be_best":0.04671
      },
      {
         "variant_name":"B",
         "x":3000,
         "y":110,
         "beats_control":0.7580899999999999,
         "to_be_best":0.7271
      }
   ]
}