AutoMLForecast is a high-level class that automates the process of selecting and tuning multiple forecasting models. It allows you to pass a dictionary of models (including specialized Auto versions of models like AutoLightGBM or AutoXGBoost) and automatically optimizes them using hyperparameter tuning.
Key features include:
- Model Ensemble/Selection: Pass multiple models to the
models argument. - Hyperparameter Tuning: Use
fit_config to define tuning logic (e.g., specifying static features). - Backtesting: Use
n_windows in .fit() to perform cross-validation/backtesting. - Prediction Intervals: Integrate
PredictionIntervals to generate uncertainty bounds. - Data Support: Works with both
pandas and polars DataFrames.
from mlforecast.auto import AutoMLForecast, AutoLightGBM, AutoRidge
from mlforecast.utils import PredictionIntervals
# Initialize AutoMLForecast
auto_mlf = AutoMLForecast(
freq=1,
season_length=season_length,
models={
'lgb': AutoLightGBM(),
'ridge': AutoRidge(),
},
fit_config=lambda trial: {'static_features': ['unique_id']},
num_threads=2,
)
# Fit with backtesting and prediction intervals
auto_mlf.fit(
df=train,
n_windows=2,
h=h,
num_samples=2,
optimize_kwargs={'timeout': 60},
fitted=True,
prediction_intervals=PredictionIntervals(n_windows=2, h=h),
)
# Predict future values
forecast = auto_mlf.predict(h, level=[80])