LinearRegressor¶
- class flexparameterize.regression.linear.LinearRegressor¶
Fits a unit’s output as an ordinary-least-squares function of its inputs.
One output column, any number of input columns, degree 1 in each (no automatic cross terms – engineer one into an
Xcolumn named"a*b"before fitting if the relationship needs one). Rows with any null acrossX/yare dropped before fitting.- coefficients¶
Fitted column name -> coefficient, plus
"intercept".
- n_samples¶
Number of rows the fit used, after dropping nulls.
- metrics¶
{"r2": ..., "rmse": ...}of the fitted line againsty.
- data_window¶
(first, last)index value of the rows used.
- input_variables¶
Column names of the fitted inputs, in order.
- output_variable¶
Column name of the fitted output.
- input_units¶
Units of every fitted input column, keyed by its column name.
- output_units¶
Units of the fitted output column.
- fit(X: DataFrame, y: DataFrame, *, input_units: dict[str, str], output_units: str) LinearRegressor¶
Fit an OLS line of
yagainstX’s columns.- Parameters:
X – One or more input columns.
y – A one-column
DataFrameholding the output.input_units – Units of every fitted input column, keyed by its column name (every column in
Xmust have an entry). Recorded forto_surrogate_spec().output_units – Units of the fitted output column. Recorded for
to_surrogate_spec().
- Returns:
self, fitted.- Raises:
FlexConfigError – If scikit-learn is not installed, or if
input_unitsis missing an entry for one ofX’s columns.FlexDataError – If
Xoryis not aDataFrame, ifydoes not hold exactly one column, or if fewer rows survive dropping nulls thanX.shape[1] + 1(the minimum an OLS fit with an intercept needs to be determined).
- to_fit_result() FitResult¶
Return this fit as the shared
FitResultshape.- Raises:
FlexDataError – If
fit()has not been called.
- to_surrogate_spec() SurrogateSpec¶
Return the fit as a
multilinearSurrogateSpec.Uses the
input_units/output_unitsrecorded byfit().- Returns:
A
SurrogateType.MULTILINEARspec built bymake_spec(): the fitted column names, verbatim, are both theinput_variableskeys and the (single-factor) terms, and every parameter is fixed.- Raises:
FlexDataError – If
fit()has not been called.