ClickHouse/docs/zh/sql-reference/aggregate-functions/reference/simplelinearregression.md
Simon Podlipsky 677f296214
docs: use k as constant name instead of a in simpleLinearRegression
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}}`
2024-10-21 15:34:15 +02:00

1.3 KiB

slug sidebar_position
/zh/sql-reference/aggregate-functions/reference/simplelinearregression 220

simpleLinearRegression

执行简单(一维)线性回归。

语法

simpleLinearRegression(x, y)

参数

  • x — x轴。
  • y — y轴。

返回值

符合y = k*x + b的常量 (k, b)

示例

SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3])
┌─arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3])─┐
│ (1,0)                                                             │
└───────────────────────────────────────────────────────────────────┘
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6])
┌─arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6])─┐
│ (1,3)                                                             │
└───────────────────────────────────────────────────────────────────┘