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

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

46 lines
1.3 KiB
Markdown
Raw Normal View History

2021-02-02 12:00:41 +00:00
---
2022-08-26 19:07:59 +00:00
slug: /zh/sql-reference/aggregate-functions/reference/simplelinearregression
2022-04-10 23:08:18 +00:00
sidebar_position: 220
2021-02-02 12:00:41 +00:00
---
# 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) │
└───────────────────────────────────────────────────────────────────┘
```