gs_quant.timeseries.statistics.LinearRegression¶
- class LinearRegression(X, y, fit_intercept=True)[source]¶
Fit an Ordinary least squares (OLS) linear regression model.
- Parameters:
X (
Union
[Series
,List
[Series
]]) – observations of the explanatory variable(s)y (
Series
) – observations of the dependent variablefit_intercept (
bool
) – whether to calculate intercept in the model
Usage
Fit OLS Model based on observations of the explanatory variables(s) X and the dependent variable y. If X and y are not aligned, only use the intersection of dates/times.
Examples
Run a linear regression on y vs. x1 and x2 and compute the R squared:
>>> x1 = generate_series(100) >>> x2 = generate_series(100) >>> y = generate_series(100) >>> r = LinearRegression([x1, x2], y, True) >>> r.r_squared()
Methods
coefficient
(i)Estimated coefficient.
fitted_values
()Fitted values computed by evaluating the regression model on the original input X.
predict
(X_predict)Use the model for prediction.
r_squared
()Coefficient of determination (R Squared)
standard_deviation_of_errors
()Standard deviation of the error term.