2020-06-18 08:24:31 +00:00
|
|
|
---
|
2022-08-28 14:53:34 +00:00
|
|
|
slug: /en/sql-reference/aggregate-functions/reference/simplelinearregression
|
2024-06-24 11:52:30 +00:00
|
|
|
sidebar_position: 183
|
2020-06-18 08:24:31 +00:00
|
|
|
---
|
|
|
|
|
2022-06-02 10:55:18 +00:00
|
|
|
# simpleLinearRegression
|
2020-06-18 08:24:31 +00:00
|
|
|
|
|
|
|
Performs simple (unidimensional) linear regression.
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
simpleLinearRegression(x, y)
|
|
|
|
```
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
2024-02-21 16:29:47 +00:00
|
|
|
- `x` — Column with explanatory variable values.
|
|
|
|
- `y` — Column with dependent variable values.
|
2020-06-18 08:24:31 +00:00
|
|
|
|
|
|
|
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) │
|
|
|
|
└───────────────────────────────────────────────────────────────────┘
|
|
|
|
```
|