Translates deployment scenarios (retraining cadence, forecast horizon, data budget) into TimeSeriesFold parameters for skforecast backtesting. Use when configuring cross-validation for model evaluation.
Ships in skforecast. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Use this skill to translate a deployment scenario (retraining cadence, forecast
horizon, data budget, ingestion delay) into TimeSeriesFold parameters.
TimeSeriesFold is the cross-validation strategy passed via the cv argument to
backtesting_forecaster (and its multi-series / stats variants) and to the
hyperparameter search functions.
from skforecast.model_selection import backtesting_forecaster, TimeSeriesFold
cv = TimeSeriesFold(
steps=7, # forecast horizon
initial_train_size=365, # first training window (required)
refit=False, # train once (default)
fixed_train_size=True, # rolling window (default)
gap=0,
)
metric, predictions = backtesting_forecaster(
forecaster=forecaster,
y=data['target'],
cv=cv,
metric='mean_absolute_error',
)
For fast hyperparameter tuning where multi-step realism is not required, use
OneStepAheadFold instead: it validates one step ahead (no recursive
prediction), so it is much faster but less representative of multi-step
performance. Use TimeSeriesFold for realistic multi-step backtesting.
forecasting-single-series / forecasting-multiple-series (have a fitted forecaster before backtesting)metric-selection (choose the metric(s) backtesting reports)hyperparameter-optimization (the same cv object drives the search functions)prediction-intervals (add interval= / interval_method= to backtest uncertainty)Scan before writing code. Each row lists a rule, the symptom when it is broken, and the recovery. Full pitfall catalog: the troubleshooting-common-errors skill.
| Rule | Symptom | Recovery |
|---|---|---|
initial_train_size must be provided (the API default is None, which only works when reusing an already-fitted forecaster) | ValueError / no training in the first fold | Pass an int, date string, or Timestamp, e.g. initial_train_size=len(y) - 100 |
initial_train_size does not accept a float fraction | ValueError: must be int, date string, Timestamp, or None | Convert fractions to an int, e.g. int(len(data) * 0.7) |
| Configuration must yield at least 2 folds | Single-fold or empty backtest | Ensure initial_train_size + gap + 2 * steps <= n_observations |
refit=True retrains every fold (slow path); the default is refit=False | Backtest much slower than expected | Use refit=False or an int cadence (e.g. refit=7) unless per-fold retraining is required |
gap, steps, and fold_stride count observations, not calendar time | Off-by-frequency delays | Convert the delay to the series frequency (e.g. 2 days at daily freq = gap=2) |
| Parameter | Type | Default | Description |
|---|---|---|---|
initial_train_size | int, str, pd.Timestamp | None (required) | Observations for initial training. Int = count, str/Timestamp = last training date. A common starting point is int(len(data) * 0.7). |
refit | bool, int | False | Refit every fold (True), train once (False, default), or every n folds (int). |
fixed_train_size | bool | True | Rolling fixed window (True, default) vs expanding window (False). |
gap | int | 0 | Observations between training end and test start. |
fold_stride | int, None | None (= steps) | Distance between consecutive test set starts. |
skip_folds | int, list, None | None | Skip folds to reduce compute. Int = keep every n-th. |
allow_incomplete_fold | bool | True | Allow final fold with fewer observations than steps. |
initial_train_size + gap + 2 * steps <= n_observationsinitial_train_size must be greater than forecaster.window_size, the number of past observations needed to build one training row (max(max_lag, max_size_window_features) plus the differentiation order). Direct forecasters (ForecasterDirect, ForecasterDirectMultiVariate, ForecasterRnn) need at least window_size + steps, using the forecaster's steps. In multi-series forecasters, each series with data in the first window needs more than window_size observations there.ForecasterEquivalentDate has window_size = offset * n_offsets (same rule); in ForecasterStats the estimator sets the minimum (window_size is fixed at 1); ForecasterFoundation accepts any value ≥ 1 (context_length is a maximum, not a minimum).gap simulates real-world delay between data availability and forecast usagefixed_train_size=True, the window rolls forward (oldest data discarded). Use for concept drift or when old data is less relevant.fixed_train_size=False, the window expands (all history retained). Use when more data always helps.predictions has, before the predicted values, the columns fold, step
(step of the forecast horizon at which each prediction was made, from
gap + 1 to gap + steps, fewer in an incomplete last fold) and y_true
(true value). Order: fold, step, y_true, pred, ...; with multiple series
level goes first, and in backtesting_stats with several estimators
estimator_id goes first. The dates without an observed value (missing
values of y in the test set) stay in predictions with y_true NaN and are
left out of the metrics, with one series and with several; in the
multi-series backtesting, every prediction column is NaN at those dates too.
The last column of metric is n_evaluated: the points used for the metrics
(true value and prediction not missing). With overlapping folds
(fold_stride < steps) each date is evaluated once, with the prediction of its
last fold, so n_evaluated is smaller than the rows of predictions. In
multi-series backtesting it is reported per level and summed in the aggregated
rows, and weighted_average is weighted by it. A level with fewer points than
the others was not predicted in some folds (short series, missing values).
Error and coverage by forecast horizon use every row, including the repeated dates of overlapping folds:
predictions = predictions.dropna(subset=['y_true'])
by_step = predictions.assign(
absolute_error=(predictions['y_true'] - predictions['pred']).abs(),
covered=predictions['y_true'].between(
predictions['lower_bound'], predictions['upper_bound']
),
).groupby('step')[['absolute_error', 'covered']].mean() # ['level', 'step'] with multiple series
| Scenario | Configuration |
|---|---|
| Retrain every time new data arrives | refit=True |
| Retrain weekly (with daily forecasts, steps=1) | refit=7 |
| Retrain monthly (with daily forecasts, steps=7) | refit=4 (every 4 folds × 7 steps ≈ monthly) |
| Retrain at each month end and forecast the whole next month (daily data) | steps=31, fold_stride=1, skip_folds = folds not starting on day 1, refit=True (see example below) |
| Never retrain / train once, evaluate across time | refit=False (fixed_train_size has no effect without refit) |
| Scenario | Configuration |
|---|---|
| Recent data more relevant (concept drift) | fixed_train_size=True |
| All historical data valuable | fixed_train_size=False (expanding) |
| Limited compute budget | refit=False or skip_folds=3 (keep every 3rd fold) |
| Scenario | Configuration |
|---|---|
| Real-time predictions (no delay) | gap=0 |
| 1-day delay between data collection and forecast | gap=1 (if freq=daily) |
| Forecast must be ready before weekend (2-day gap) | gap=2 |
| Scenario | Configuration |
|---|---|
| Default (balanced) | int(len(data) * 0.7) |
| Maximize evaluation coverage | Hard minimum (window_size + 1; window_size + steps for direct) plus a learning margin, see Constraints |
| Maximize training data | n_observations - gap - 2 * steps (minimum 2 folds) |
| Start from specific date | initial_train_size="2023-01-01" |
| Conservative (large training set) | int(len(data) * 0.8) |
| Scenario | Configuration |
|---|---|
| Non-overlapping evaluation (default) | fold_stride=None (equals steps) |
| Sliding window evaluation (1-step shift) | fold_stride=1 |
| Sparse evaluation (save compute) | fold_stride=steps * 2 |
refit = True
fixed_train_size = False # Keep all history
gap = 0 # No delay
fold_stride = None # Non-overlapping weeks
refit = False # Train once; fixed_train_size has no effect without refit
gap = 0
gap = 2
refit = True
refit = True
skip_folds = 2 # Keep every 2nd fold
Folds count observations, not calendar months. Create one candidate fold per day and skip those that do not start predicting on day 1 of a month:
gap = 0
first_origin = '2025-09-30' # month end (minus `gap` days): fold 0 cannot be skipped
n_train = y.index.get_loc(first_origin) + 1
skip_folds = [
i for i, date in enumerate(y.index[n_train + gap:]) if not date.is_month_start
] # fold i predicts from position n_train + gap + i
cv = TimeSeriesFold(
steps=31, # longest month
initial_train_size=first_origin,
fold_stride=1,
gap=gap,
skip_folds=skip_folds,
refit=True,
fixed_train_size=False,
allow_incomplete_fold=True,
)
is_month_start
is True for every hour of day 1: also require date == date.normalize() and set
steps to the observations of the longest month (744 for hourly data).ForecasterDirect and ForecasterDirectMultiVariate need steps >= 31 + gap.refit=True (retrain every month) or refit=False (train once). An integer
refit counts the daily candidate folds, not months: refit=3 does not retrain
every 3 months.predictions repeats the dates where months shorter than 31 days spill into the
next month. Remove them before grouping by month or plotting (the error of
each month is then (predictions['pred'] - predictions['y_true']).abs()):
predictions[~predictions.index.duplicated(keep='last')] for a single series;
with multiple series (long format with a level column), deduplicate by date and
level, predictions[~predictions.set_index('level', append=True).index.duplicated(keep='last')].fold column keeps the numbering of the daily folds (0, 31, 61, ...).verbose=False: verbose=True prints every skipped fold.# Hard minimum: forecaster.window_size + 1 (window_size + 12 for ForecasterDirect with steps=12)
initial_train_size = forecaster.window_size + margin # margin: rows to learn from, e.g. 2+ seasonal cycles
refit = False # Faster; trains once, fixed_train_size has no effect
fold_stride = 1 # Sliding window (many overlapping folds)
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/skforecast:backtesting-configurationfrom skforecast
npx claudepluginhub skforecast/skforecast --plugin skforecast17 skills in this plugin
/autocorrelation-and-lag-selectionAnalyzes time series dynamics with the fast skforecast.stats functions acf, pacf and calculate_lag_autocorrelation. Covers reading ACF/PACF patterns to identify AR/MA orders and seasonality, ranking lags by partial autocorrelation, and feeding the result to the lags argument of any skforecast forecaster. Use when the user wants to understand the dynamics of a series, choose a candidate set of lags before hyperparameter tuning, or replace a slow statsmodels acf/pacf call.
/baseline-forecastingBuilds and evaluates simple baseline forecasts with ForecasterEquivalentDate (equivalent-date / seasonal-naive / moving-average) to benchmark machine learning models. Covers offset (int vs pandas DateOffset), n_offsets with agg_func, backtesting a baseline, comparing against ML with MASE, conformal intervals, and grid_search_equivalent_date. Use when the user wants a baseline, a naive or seasonal reference, or to check whether a model beats a simple rule. Not for choosing among ML forecasters (see choosing-a-forecaster) or tuning ML hyperparameters (see hyperparameter-optimization).
/choosing-a-forecasterGuides selection of the appropriate skforecast forecaster based on the user's data characteristics and requirements. Provides a decision matrix mapping use cases to forecaster classes. Use when the user is unsure which forecaster to use or asks for a recommendation.
/complete-api-referenceProvides complete constructor and method signatures for all skforecast forecasters, backtesting functions, search functions, cross-validation classes, preprocessing, feature selection, and drift detection. Use when the user needs exact parameter names, types, or defaults for any skforecast class or function.
/deep-learning-forecastingForecasts time series using recurrent neural networks (RNN, LSTM, GRU) with ForecasterRnn and the create_and_compile_model helper. Covers model architecture, training, and multi-series deep learning. Use when the user wants to use deep learning / neural networks for time series forecasting.
/drift-detectionDetects data drift in time series forecasting pipelines using RangeDriftDetector and PopulationDriftDetector. Covers range-based out-of-range detection and statistical distribution tests. Use when the user wants to monitor model reliability in production.
Other plugins' skills for the same job