> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 执行简单（一维）线性回归。

# simpleLinearRegression

<div id="simpleLinearRegression">
  ## simpleLinearRegression
</div>

引入版本：v20.1.0

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

**语法**

```sql theme={null}
simpleLinearRegression(x, y)
```

**参数**

* `x` — 包含自变量值的列。[`Float64`](/zh/reference/data-types/float)
* `y` — 包含因变量值的列。[`Float64`](/zh/reference/data-types/float)

**返回值**

返回拟合直线 `y = k*x + b` 的常数 `(k, b)`。[`Tuple(Float64, Float64)`](/zh/reference/data-types/tuple)

**示例**

**完美线性拟合**

```sql title=Query theme={null}
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3]);
```

```response title=Response theme={null}
┌─arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3])─┐
│ (1,0)                                                             │
└───────────────────────────────────────────────────────────────────┘
```

**带偏移量的线性拟合**

```sql title=Query theme={null}
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6]);
```

```response title=Response theme={null}
┌─arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6])─┐
│ (1,3)                                                             │
└───────────────────────────────────────────────────────────────────┘
```
