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

45 lines
1.2 KiB
Markdown
Raw Normal View History

2021-02-02 12:00:41 +00:00
---
toc_priority: 220
---
# simpleLinearRegression {#simplelinearregression}
2021-02-25 14:21:42 +00:00
执行简单(一维)线性回归。
**语法**
2021-02-02 12:00:41 +00:00
``` sql
simpleLinearRegression(x, y)
```
2021-02-25 14:21:42 +00:00
**参数**
2021-02-02 12:00:41 +00:00
2021-02-25 14:21:42 +00:00
- `x` — x轴。
- `y` — y轴。
2021-02-02 12:00:41 +00:00
2021-02-25 14:21:42 +00:00
**返回值**
2021-02-02 12:00:41 +00:00
2021-02-25 14:21:42 +00:00
符合`y = a*x + b`的常量 `(a, b)`
2021-02-02 12:00:41 +00:00
2021-02-25 14:21:42 +00:00
**示例**
2021-02-02 12:00:41 +00:00
``` 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) │
└───────────────────────────────────────────────────────────────────┘
```