This page

Citing

Please consider citing the scikit-learn.

9.2.1. sklearn.linear_model.LinearRegression

class sklearn.linear_model.LinearRegression(fit_intercept=True, normalize=False, overwrite_X=False)

Ordinary least squares Linear Regression.

Notes

From the implementation point of view, this is just plain Ordinary Least Squares (numpy.linalg.lstsq) wrapped as a predictor object.

Attributes

coef_ array Estimated coefficients for the linear regression problem.
intercept_ array Independent term in the linear model.

Methods

fit(X, y) Fit linear model.
predict(X) Predict using the linear model
score(X, y) Returns the coefficient of determination of the prediction
set_params(**params) Set the parameters of the estimator.
__init__(fit_intercept=True, normalize=False, overwrite_X=False)
fit(X, y)

Fit linear model.

Parameters :

X : numpy array of shape [n_samples,n_features]

Training data

y : numpy array of shape [n_samples]

Target values

fit_intercept : boolean, optional

wether to calculate the intercept for this model. If set to false, no intercept will be used in calculations (e.g. data is expected to be already centered).

normalize : boolean, optional

If True, the regressors X are normalized

Returns :

self : returns an instance of self.

predict(X)

Predict using the linear model

Parameters :

X : numpy array of shape [n_samples, n_features]

Returns :

C : array, shape = [n_samples]

Returns predicted values.

score(X, y)

Returns the coefficient of determination of the prediction

Parameters :

X : array-like, shape = [n_samples, n_features]

Training set.

y : array-like, shape = [n_samples]

Returns :

z : float

set_params(**params)

Set the parameters of the estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns :self :