Contents

6.2.1. scikits.learn.linear_model.LinearRegression

class scikits.learn.linear_model.LinearRegression(fit_intercept=True)

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
predict
score
__init__(fit_intercept=True)
fit(X, y, **params)

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).

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