Files
2026-08-05 13:53:42 +00:00

71 lines
7.4 KiB
Markdown

# Linear Regression Model
Linear regression model for time series analysis, with optional polynomial features and clipping support.
## Model Parameters (`LinearRegressionModel`)
These parameters are defined in the `model.yaml` under `model.input_map` and are also represented in `schemas.yaml` under `components.schemas.model` with concrete `example` values used during automated validation:
| Parameter | Example | Description |
|--------------------|---------|-----------------------------------------------------------------------------|
| `degree` | `2` | Degree of the polynomial used to create polynomial features. |
| `interaction_only` | `true` | Whether to include only interaction features in polynomial features. |
| `verbose` | `true` | Enable verbose output during model execution. |
| `clipping_max` | `100` | Maximum value for clipping prediction output. |
| `clipping_min` | `0` | Minimum value for clipping prediction output. |
## Data Preprocessor (`DataPreprocessor`)
These parameters are defined in the `model.yaml` under `data_model.input_map` and are also represented in `schemas.yaml` under `components.schemas.data_model` with concrete `example` values used during automated validation:
| Parameter | Example | Description |
|----------------------|--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| `scaler__name` | `'Standard Scaler'` | Name of the scaler to use for scaling the data. Options: 'Standard Scaler' |
| `verbose` | `true` | Enable verbose output during model execution. |
| `steps_order` | `['Discontinuity Treatment', 'Lag Selection', 'Range Selection & Data Removal', 'Static Window Removal', 'Define Variables Limits', 'Normalization', 'Feature Creation', 'Lag Creation']` | Order of the steps to be executed in the pipeline. |
| `nan_treatment` | `'drop'` | The treatment for missing values. Options: 'drop', 'linear interpolation' |
| `lag_train` | `{'variable_name': 1}` | The lags for each variable to be applyed during training. |
| `lag_transform` | `{'variable_name': 1}` | The lags for each variable to be applyed during transformation. |
| `start_date` | `'2020-01-01 00:00:00'` | The start date for the dataset. Format: 'YYYY-MM-DD HH:MM:SS' |
| `end_date` | `'2020-01-01 00:00:00'` | The end date for the dataset. Format: 'YYYY-MM-DD HH:MM:SS' |
| `removed_intervals` | `[(2020-01-01 00:00:00, 2020-01-01 00:00:00)]` | The intervals to be removed from the dataset. |
| `static_threshold` | `10` | The number of repeated values to be considered as static. |
| `lower_limits` | `{'variable_name': 0}` | The lower limits for each variable. |
| `upper_limits` | `{'variable_name': 1}` | The upper limits for each variable. |
| `scaler_name` | `'Standard Scaler'` | The scaler name. Options: 'None', 'Standard Scaler' |
| `scaler_params` | `{'variable_name': {'mean': 0, 'variance': 1}}` | The parameters for the scaler object, if it is used. |
| `self_operations` | `['variable_name_exp_scalar']` | The operations for feature creation using the same variable. |
| `cross_operations` | `['variable_name1_mul_variable_name2']` | The operations for feature creation using two variables. |
| `created_lags` | `{'variable_name': [1, 2]}` | Variables created by lagging existing ones. |
## Lifecycle (train / retrain)
The wrapper follows the `SientiaModel` interface. Data is always passed as full DataFrames (features + target).
- **`train(train_data, val_data, target)`**
- `train_data`: full training DataFrame (features + target column).
- `val_data`: full validation DataFrame (features + target column).
- `target`: name of the target column (must exist in both).
The base class fits the transformer on the full datasets, then transforms and fits the model on transformed features and target.
- **`retrain(data)`**
- `data`: full dataset (features + target column).
Uses `self.target` set during `train()`. Call only after `train()` has been run.
Neither method mutates the passed DataFrames.
## Usage Notes
- If `variable_columns` is not set, it is inferred during `fit` as all columns except the target.
- Polynomial features are created automatically when `degree > 1`.
- `clipping` uses Q1/Q3 of the training target when replacing out-of-bounds predictions.
- The wrapper enforces that `wrapper.target` is set before training or retraining; otherwise, a `ValueError` is raised to fail fast when the configuration is incomplete.
All parameters documented above **must stay in sync** between:
- This README
- `model.yaml` (`model.input_map` and `data_model.input_map`)
- `schemas.yaml` (`components.schemas.model` and `components.schemas.data_model`)
In particular, `schemas.yaml` must contain **complete and coherent examples** for every parameter that affects runtime behaviour, since those examples are used to build `model_kwargs` and `transformer_kwargs` during validation. Parameters without examples may not be fully exercised by the automated validation flow.