How to Forecast with CatBoost¶
This guide shows you how to use CatBoost as the estimator inside Yohou's reduction forecasters for point, interval, and categorical predictions.
Prerequisites¶
- Familiarity with the fit/predict API (Getting Started)
- CatBoost installed (
pip install catboost) - Understanding of reduction forecasting (Reduction Forecasting)
Try it interactively
Plug CatBoostRegressor into PointReductionForecaster as a drop-in sklearn estimator, compare gradient-boosted versus Ridge linear baseline, and demonstrate the direct reduction strategy with tree-based models.
ViewOpen in marimoUse IntervalReductionForecaster with CatBoost's native multiquantile objective for simultaneous lower and upper bound estimation.
ViewOpen in marimoFit a Point Forecaster¶
Pass a CatBoostRegressor to PointReductionForecaster. Any CatBoostRegressor parameter (learning rate, depth, regularization) can be set directly:
from catboost import CatBoostRegressor
from yohou.datasets import fetch_electricity_demand
from yohou.point import PointReductionForecaster
from yohou.preprocessing import LagTransformer
data = fetch_electricity_demand()
y = data.frame
forecaster = PointReductionForecaster(
estimator=CatBoostRegressor(iterations=500, verbose=0),
feature_transformer=LagTransformer(lag=[1, 3, 6, 12]),
)
forecaster.fit(y, forecasting_horizon=12)
predictions = forecaster.predict()
Choose a Reduction Strategy¶
The reduction_strategy parameter controls how horizons are modelled. If each horizon benefits from its own model, use "direct". Set n_jobs=-1 to train the per-step models in parallel:
forecaster = PointReductionForecaster(
estimator=CatBoostRegressor(iterations=500, verbose=0),
feature_transformer=LagTransformer(lag=[1, 3, 6, 12]),
reduction_strategy="direct",
n_jobs=-1,
)
If you want a single model that predicts all horizons at once, keep the default "multi-output". If you need direct models with recursive feature propagation between steps, use "dir-rec". See Build Reduction Forecasters for a full comparison.
Produce Interval Forecasts¶
Pass a CatBoostRegressor to IntervalReductionForecaster and specify coverage_rates at fit time. The framework automatically configures CatBoost's MultiQuantile loss with the correct alpha values:
from yohou.interval import IntervalReductionForecaster
forecaster = IntervalReductionForecaster(
estimator=CatBoostRegressor(iterations=500, verbose=0),
feature_transformer=LagTransformer(lag=[1, 3, 6, 12]),
)
forecaster.fit(y, forecasting_horizon=12, coverage_rates=[0.90])
intervals = forecaster.predict_interval()
To request multiple coverage rates at once, pass them as a list:
Forecast Categorical Data¶
Pass a CatBoostClassifier to ClassProbaReductionForecaster for categorical time series (for example, demand tiers or quality levels):
from catboost import CatBoostClassifier
from yohou.class_proba import ClassProbaReductionForecaster
from yohou.datasets import fetch_air_quality_classification
from yohou.preprocessing import LagTransformer
data = fetch_air_quality_classification()
y_categorical = data.y
forecaster = ClassProbaReductionForecaster(
estimator=CatBoostClassifier(iterations=500, verbose=0),
feature_transformer=LagTransformer(lag=[1, 3, 6, 12]),
)
forecaster.fit(y_categorical, forecasting_horizon=12)
y_proba = forecaster.predict_class_proba()
y_labels = forecaster.predict()
See Forecast with Class Probabilities for evaluation and scoring details.
Tune CatBoost with Randomized Search¶
Use Yohou's RandomizedSearchCV to search over CatBoost parameters:
from yohou.model_selection import RandomizedSearchCV, ExpandingWindowSplitter
param_distributions = {
"estimator__iterations": [200, 500, 1000],
"estimator__depth": [4, 6, 8],
"estimator__l2_leaf_reg": [1, 3, 10],
}
search = RandomizedSearchCV(
forecaster=forecaster,
param_distributions=param_distributions,
cv=ExpandingWindowSplitter(n_splits=3),
n_iter=10,
)
search.fit(y, forecasting_horizon=12)
best_forecaster = search.best_forecaster_
For exhaustive search, use GridSearchCV instead. See Tune Hyperparameters for details.
See Also¶
- Reduction Forecasting for the conceptual background on reduction strategies
- Interval Forecasting for interval prediction concepts
- Build Reduction Forecasters for combining estimators, transformers, and strategies