SIENTIAPDE-1430: Introduce static_threshold parameter for static window removal.

This parameter allows customizing the threshold (1-1000) used when rem_static_win is enabled, defaulting to 1 if null.
Updates include parameter definition, business rule validation, repository logic for passing the threshold, documentation in README.md and PIPELINE_PARAMS_CHANGELOG.md, and new unit and integration tests.
This commit is contained in:
Bruno Domingues
2025-12-19 15:44:18 -03:00
parent 7cbb7022e5
commit 06571011f2
10 changed files with 174 additions and 3 deletions

View File

@@ -47,6 +47,7 @@ class TrainModelParams:
end_date (str | None): End date for filtering data.
scaler_name (str): Name of the scaler to use ('Standard Scaler' or 'None').
support_filters (dict): Custom support filters per variable.
static_threshold (int | None): Threshold for static window removal (1-1000). Only used when rem_static_win is True.
"""
variable_columns: list[str]
@@ -76,6 +77,7 @@ class TrainModelParams:
end_date: str | None
scaler_name: str
support_filters: dict
static_threshold: int | None
@classmethod
def from_dict(cls, data: dict[str, Any]) -> 'TrainModelParams':
@@ -138,6 +140,7 @@ class TrainModelParams:
scaler_name=cls._check_none(data.get('scaler_name'), str, 'scaler_name'),
support_filters=cls._check_type(data.get('support_filters'), dict, 'support_filters')
or {},
static_threshold=cls._check_type(data.get('static_threshold'), int, 'static_threshold'),
)
@staticmethod
@@ -228,6 +231,13 @@ class TrainModelParams:
if self.window < 0:
raise ValueError(f'window must be non-negative, got {self.window}')
# Validate static_threshold only when rem_static_win is True and value is provided
if self.rem_static_win and self.static_threshold is not None:
if not 1 <= self.static_threshold <= 1000:
raise ValueError(
f'static_threshold must be between 1 and 1000, got {self.static_threshold}'
)
def _validate_model_params(self) -> None:
"""Validate model-related parameters."""
if self.degree < 1:

View File

@@ -206,7 +206,10 @@ class ModelRepository:
self.model_serving.log_param('lag_train', data.params.lag_train)
self.model_serving.log_param('lag_transform', data.params.lag_val)
self.model_serving.log_param(
'static_threshold', 1 if data.params.rem_static_win else None
'static_threshold',
(data.params.static_threshold if data.params.static_threshold is not None else 1)
if data.params.rem_static_win
else None,
)
self.model_serving.log_param('lower_limits', data.params.low_lim)
self.model_serving.log_param('upper_limits', data.params.upp_lim)

View File

@@ -269,7 +269,9 @@ class TrainingRepository:
start_date=params.start_date,
end_date=params.end_date,
removed_intervals=removed_intervals,
static_threshold=1 if params.rem_static_win else None,
static_threshold=(params.static_threshold if params.static_threshold is not None else 1)
if params.rem_static_win
else None,
low_lim=params.low_lim,
upp_lim=params.upp_lim,
scaler_name=params.scaler_name,