Skip to content

OLSModel

OLSModel

Ordinary Least Squares linear regression using scikit-learn’s LinearRegression.

Basic Usage

from epftoolbox2.models import OLSModel
model = OLSModel(
predictors=[
"load_actual",
"is_monday_d+{horizon}",
"is_tuesday_d+{horizon}",
"is_wednesday_d+{horizon}",
"is_thursday_d+{horizon}",
"is_friday_d+{horizon}",
"is_saturday_d+{horizon}",
"is_sunday_d+{horizon}",
"is_holiday_d+{horizon}",
"daylight_hours_d+{horizon}",
],
training_window=365,
name="OLS",
)

Parameters

ParameterTypeDefaultDescription
predictorsListRequiredPredictor specifications (strings, {horizon} templates, or callables)
training_windowint365Days of training data
namestr"Model"Display name for reports

Callable predictors accept (horizon) or (horizon, hour) — the two-parameter form enables features that differ by hour of day:

# horizon-only
lambda horizon: f"price_lag_d-{horizon-7}"
# horizon + hour of day
lambda horizon, hour: f"load_h{hour:02d}_d+{horizon}"

Example

from epftoolbox2.pipelines import ModelPipeline
from epftoolbox2.models import OLSModel
from epftoolbox2.evaluators import MAEEvaluator
from epftoolbox2.exporters import TerminalExporter
predictors = [
"load_actual",
"is_monday_d+{horizon}",
"is_tuesday_d+{horizon}",
"is_wednesday_d+{horizon}",
"is_thursday_d+{horizon}",
"is_friday_d+{horizon}",
"is_saturday_d+{horizon}",
"is_sunday_d+{horizon}",
"is_holiday_d+{horizon}",
"daylight_hours_d+{horizon}",
*[f"load_actual_d-{i}" for i in [1, 7]],
]
pipeline = (
ModelPipeline()
.add_model(OLSModel(predictors=predictors, name="OLS"))
.add_evaluator(MAEEvaluator())
.add_exporter(TerminalExporter())
)
report = pipeline.run(data=df, test_start="2024-02-01", test_end="2024-03-01")