mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-14 18:32:29 +00:00
677f296214
Function uses `k` internally. E.g. ```sql SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3]) FORMAT JsonEachRow ``` outputs `{"arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3])":{"k":1,"b":0}}`
44 lines
1.3 KiB
Markdown
44 lines
1.3 KiB
Markdown
---
|
|
slug: /en/sql-reference/aggregate-functions/reference/simplelinearregression
|
|
sidebar_position: 183
|
|
---
|
|
|
|
# simpleLinearRegression
|
|
|
|
Performs simple (unidimensional) linear regression.
|
|
|
|
``` sql
|
|
simpleLinearRegression(x, y)
|
|
```
|
|
|
|
Parameters:
|
|
|
|
- `x` — Column with explanatory variable values.
|
|
- `y` — Column with dependent variable values.
|
|
|
|
Returned values:
|
|
|
|
Constants `(k, b)` of the resulting line `y = k*x + b`.
|
|
|
|
**Examples**
|
|
|
|
``` sql
|
|
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3])
|
|
```
|
|
|
|
``` text
|
|
┌─arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3])─┐
|
|
│ (1,0) │
|
|
└───────────────────────────────────────────────────────────────────┘
|
|
```
|
|
|
|
``` sql
|
|
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6])
|
|
```
|
|
|
|
``` text
|
|
┌─arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6])─┐
|
|
│ (1,3) │
|
|
└───────────────────────────────────────────────────────────────────┘
|
|
```
|