fix(ml): resolve km_open under-prediction and remove Rule 3

- Removed data leakage features (lifts_open, snow_depth) from ML training.
- Added station_id as an encoded categorical feature to enable station-awareness.
- Removed Rule 3 (warm rain reduction) from the rules engine to avoid double-penalization.
- Retrained all models with the corrected feature set.
This commit is contained in:
dasemu committed 2026-03-13 10:01:43 +01:00
1 parent 6aa37f88e7
commit b5b62e582e
3 files changed
+37 -39

No files matched your search

+6 -37
View File
@@ -19,21 +19,12 @@ logger = logging.getLogger(__name__)
# Path relative to repository root
_CONFIG_PATH = Path(__file__).parent.parent / "config" / "stations.yaml"
# Temperature above which rain becomes operationally problematic
_RAIN_TEMPERATURE_THRESHOLD_C = 10.0
# Precipitation threshold (mm) to be considered rain at high temperature
_RAIN_PRECIPITATION_THRESHOLD_MM = 2.0
# Fresh snowfall (cm in 24 h) considered "heavy"
_HEAVY_FRESH_SNOW_THRESHOLD_CM = 20.0
# Wind gust (km/h) considered "moderate" when combined with heavy snow
_MODERATE_WIND_THRESHOLD_KMH = 40.0
# km_factor reduction applied when warm rain is detected
_WARM_RAIN_KM_FACTOR_REDUCTION = 0.4
def _load_station_configs() -> dict[str, Any]:
"""Load all station configurations from stations.yaml.
@@ -187,29 +178,7 @@ class RulesEngine:
min_snow,
)
# ---- Rule 3: High temperature + rain -> reduce km_factor ---------
temp_max = weather_data.get("temperature_2m_max")
precip = weather_data.get("precipitation_sum", 0.0)
if (
temp_max is not None
and temp_max > _RAIN_TEMPERATURE_THRESHOLD_C
and precip > _RAIN_PRECIPITATION_THRESHOLD_MM
):
km_factor = max(0.0, km_factor - _WARM_RAIN_KM_FACTOR_REDUCTION)
reasons.append(
f"Temperatura de {temp_max:.1f} °C (superior a {_RAIN_TEMPERATURE_THRESHOLD_C} °C) "
f"con {precip:.1f} mm de precipitación; se estima una reducción de pistas abiertas."
)
logger.info(
"[%s] Rule 3 fired: temp %.1f °C + rain %.1f mm -> km_factor reduced to %.2f",
station_name,
temp_max,
precip,
km_factor,
)
# ---- Rule 4: Heavy fresh snow + moderate wind -> likely open -----
# ---- Rule 3: Heavy fresh snow + moderate wind -> likely open -----
snowfall_24h = weather_data.get("snowfall_sum")
wind_speed = weather_data.get("wind_gusts_10m_max", 0.0)
@@ -226,13 +195,13 @@ class RulesEngine:
f"({wind_speed:.1f} km/h); es muy probable que la estación abra y esté concurrida."
)
logger.info(
"[%s] Rule 4 fired: heavy snow %.1f cm + wind %.1f km/h -> force_open",
"[%s] Rule 3 fired: heavy snow %.1f cm + wind %.1f km/h -> force_open",
station_name,
snowfall_24h,
wind_speed,
)
# ---- Rule 5: Weekday + no fresh snow -> low crowd ----------------
# ---- Rule 4: Weekday + no fresh snow -> low crowd ----------------
is_weekend = bool(weather_data.get("is_weekend", False))
is_holiday = bool(weather_data.get("is_holiday", False))
is_busy_day = is_weekend or is_holiday
@@ -242,16 +211,16 @@ class RulesEngine:
reasons.append(
"Día laborable sin nevadas significativas; se espera un nivel de afluencia bajo."
)
logger.debug("[%s] Rule 5 fired: weekday + no fresh snow -> low crowd", station_name)
logger.debug("[%s] Rule 4 fired: weekday + no fresh snow -> low crowd", station_name)
# ---- Rule 6: Weekend/holiday + fresh snow -> high crowd ----------
# ---- Rule 5: Weekend/holiday + fresh snow -> high crowd ----------
if is_busy_day and snowfall_24h is not None and snowfall_24h >= 5.0 and not force_closed:
reasons.append(
f"Fin de semana o festivo con {snowfall_24h:.1f} cm de nieve fresca; "
"se espera un nivel de afluencia alto."
)
logger.debug(
"[%s] Rule 6 fired: busy day + fresh snow %.1f cm -> high crowd",
"[%s] Rule 5 fired: busy day + fresh snow %.1f cm -> high crowd",
station_name,
snowfall_24h,
)