LinearRegression

LinearRegression(
    alpha=0.0,
    l1_ratio=0.0,
    fit_intercept=True,
    max_iterations=1000,
    tolerance=1e-08,
    l1_smoothing=1e-06,
)

Linear regression estimated by direct optimization of squared loss.

The fitted model minimizes the average squared-error objective. When alpha > 0, the optimization backend switches to Frank-Wolfe over an exact L1 or L2 ball, depending on l1_ratio. For unregularized fits, both classical and robust sandwich covariance estimators are available.

Attributes

Name Type Description
coef_ ndarray of shape (n_features,) Estimated slope coefficients.
intercept_ float Estimated intercept. Equals 0.0 when fit_intercept=False.
params_ ndarray of shape (n_params,) Full parameter vector, including the intercept when present.
std_errors_ ndarray or None Classical standard errors for params_.
robust_std_errors_ ndarray or None Heteroskedasticity-robust sandwich standard errors for params_.

Methods

Name Description
confidence_intervals Return coefficient confidence intervals.
fit Fit the linear regression model.
predict Predict the conditional mean response.
score Return the coefficient of determination, R^2.
summary Return [coef, se, ci_lb, ci_ub] for each fitted parameter.

confidence_intervals

LinearRegression.confidence_intervals(alpha=0.05, covariance_type='nonrobust')

Return coefficient confidence intervals.

Parameters

Name Type Description Default
alpha float Two-sided significance level. 0.05
covariance_type ('nonrobust', 'robust') Covariance estimator used to construct intervals. "nonrobust"

Returns

Name Type Description
ndarray of shape (n_params, 2) Lower and upper confidence bounds for each fitted parameter.

fit

LinearRegression.fit(X, y)

Fit the linear regression model.

Parameters

Name Type Description Default
X ndarray of shape (n_samples, n_features) Feature matrix. required
y ndarray of shape (n_samples,) Response vector. required

Returns

Name Type Description
LinearRegression The fitted estimator.

predict

LinearRegression.predict(X)

Predict the conditional mean response.

Parameters

Name Type Description Default
X ndarray of shape (n_samples, n_features) Feature matrix. required

Returns

Name Type Description
ndarray of shape (n_samples,) Predicted mean response.

score

LinearRegression.score(X, y)

Return the coefficient of determination, R^2.

Parameters

Name Type Description Default
X ndarray of shape (n_samples, n_features) Feature matrix. required
y ndarray of shape (n_samples,) Observed response vector. required

Returns

Name Type Description
float The in-sample R^2 statistic.

summary

LinearRegression.summary(alpha=0.05, covariance_type='nonrobust')

Return [coef, se, ci_lb, ci_ub] for each fitted parameter.