# dislib.regression.LinearRegression¶

class `dislib.regression.linear.base.``LinearRegression`(arity=50)[source]

Bases: `sklearn.base.BaseEstimator`

Simple linear regression using ordinary least squares.

model: y1 = alpha + beta*x_i + epsilon_i

goal: y = alpha + beta*x

Parameters: arity (int, optional (default=50)) – Arity of the reductions. coef (array, shape (n_features, )) – Estimated coefficient (beta) in the linear model. intercept (float) – Estimated independent term (alpha) in the linear model.

Examples

```>>> import numpy as np
>>> import dislib as ds
>>> from dislib.regression import LinearRegression
>>> from pycompss.api.api import compss_wait_on
>>> x_data = np.array([1, 2, 3, 4, 5]).reshape(-1, 1)
>>> y_data = np.array([2, 1, 1, 2, 4.5]).reshape(-1, 1)
>>> bn, bm = 2, 2
>>> x = ds.array(x=x_data, block_size=(bn, bm))
>>> y = ds.array(x=y_data, block_size=(bn, bm))
>>> reg = LinearRegression()
>>> reg.fit(x, y)
>>> # y = 0.6 * x + 0.3
>>> reg.coef_
0.6
>>> reg.intercept_
0.3
>>> x_test = np.array([3, 5]).reshape(-1, 1)
>>> test_data = ds.array(x=x_test, block_size=(bn, bm))
>>> pred = reg.predict(test_data).collect()
>>> pred
array([2.1, 3.3])
```
`fit`(x, y)[source]

Fit the linear model.

Parameters: x (ds-array) – Samples to be used to fit the model y (ds-array) – Labels of the samples `NotImplementedError` – If x is a sparse array.
`predict`(x)[source]

Predict using the linear model.

Parameters: x (ds-array) – Samples to be predicted: x.shape (n_samples, 1). y – Predicted values ds-array `NotImplementedError` – If x is a sparse array.