linear_regression
linear_regression(x, y, intercept=True)Ordinary least squares by singular value decomposition.
Mirrors the C# LinearRegression class of the Numerics library: estimates Y = alpha + beta*X + e, e ~ N(0, sigma), via SVD.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | array_like | A 2D array of predictors with one row per observation, or a 1D array for a single predictor. | required |
| y | array_like | Responses, one per row of x. |
required |
| intercept | bool | Whether to fit an intercept. Default True. |
True |
Returns
| Name | Type | Description |
|---|---|---|
| LinearRegressionResult |
Examples
>>> from corehydropy import linear_regression
>>> x = [[1, 2], [2, 1], [3, 4], [4, 3], [5, 5]]
>>> y = [3.1, 4.2, 8.1, 9.2, 13.0]
>>> fit = linear_regression(x, y)
>>> round(float(fit.r_squared), 6)
0.997992