ClickHouse/docs/en/sql-reference/aggregate-functions/reference/simplelinearregression.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.3 KiB
Markdown
Raw Normal View History

---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/aggregate-functions/reference/simplelinearregression
sidebar_position: 183
---
2022-06-02 10:55:18 +00:00
# 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 `(a, b)` of the resulting line `y = a*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) │
└───────────────────────────────────────────────────────────────────┘
```