Data Science
What this does: Finds the best model settings automatically using Bayesian optimization, improving prediction accuracy without manual trial-and-error — saving days of data science effort per training cycle.
Training Pipeline
1
Data Preparation
Features are engineered with time-based lags and rolling windows. Data is split using a chronological 80/20 split (preserving temporal order) to prevent look-ahead bias, ensuring the model is always evaluated on future data relative to the training set.
2
Hyperparameter Optimization
Optuna explores the search space using a . Unpromising trials are pruned early using a
MedianPruner.3
Production Model Selection
The trial with the lowest RMSE is selected as the winner. The final model is retrained on the full dataset using the best hyperparameters found.
Persistent Optimization
Unlike standard in-memory optimization, our system persists the entire state of the hyperparameter search to a PostgreSQL database.Key Benefits
- Resume Capability: If the pipeline crashes, it resumes from where it left off.
- Parallel Execution: Multiple Airflow workers can run trials concurrently.
- Historical Analysis: Query the database later to analyze hyperparameter trends.
Implementation
Configuration
Persistence: Optuna studies are saved to
postgresql://airflow:airflow@postgres:5432/optuna.Advanced Training Modes
The DAG supports two additional training strategies, enabled viaparameters.yml:
- Multi-Objective
- Ensemble
Finds Pareto-optimal solutions balancing multiple metrics (RMSE and MAE).
- Trials: 50 (configurable via
multi_objective_trials) - Weights: RMSE 60%, MAE 40%
- Enable:
advanced_features.enable_multi_objective: true
Model Comparison
The pipeline also trains a Random Forest baseline via thedemand_modeling Kedro pipeline and compares it head-to-head against CatBoost using RMSE, MAE, and MAPE. The winning model is selected automatically.
Evaluation Metrics
We prioritize RMSE for optimization, but monitor multiple metrics for business context.- RMSE
- MAPE (Zero-Safe)
- MAE
Root Mean Squared Error: The primary objective function. It penalizes larger errors more heavily.
Optuna Visualization
MLflow Integration
All training runs are automatically logged to the MLflow Tracking Server.- Model Registry: Models are registered under
demand_forecasting_catboost. - Metrics:
cv_rmse_mean,final_rmse,final_mae,final_mape. - Artifacts: Code snapshots,
regressor.pickle.
Related Pages
Parameters
Full search space configuration and feature engineering settings.
Experiment Tracking
MLflow integration for logging metrics, artifacts, and model registry.
