Forecasts a single time series using skforecast's ForecasterRecursive or ForecasterDirect. Covers data preparation, model creation, training, prediction, backtesting, and prediction intervals.
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 workflow when you have one time series and want to predict its future values.
choosing-a-forecaster (decide between Recursive and Direct based on the data)autocorrelation-and-lag-selection (pick the lags argument from ACF/PACF analysis)feature-engineering (assemble the rolling, calendar, and exogenous features)baseline-forecasting (establish a naive reference to benchmark the model against)hyperparameter-optimization (tune the forecaster once a baseline is trained)prediction-intervals (add bootstrap or conformal intervals on top of the point forecasts)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 |
|---|---|---|
| Set the index frequency before fitting | ValueError: ... must be a DatetimeIndex with frequency | Call data = data.asfreq('h') (or the correct alias) on y and exog |
exog passed to predict() must cover every future step | exog length / index error, or the forecast stops short | Slice exog to the full horizon: one row per step, dates matching the forecast |
Fit with store_in_sample_residuals=True before predict_interval(method='bootstrapping') | No in-sample residuals stored / empty residuals | Refit: forecaster.fit(y=y_train, store_in_sample_residuals=True) |
| Split chronologically, never shuffle | Over-optimistic metrics, leakage | Use a time-ordered split (TimeSeriesFold); do not random-split |
import pandas as pd
from sklearn.ensemble import RandomForestRegressor
from skforecast.recursive import ForecasterRecursive
from skforecast.preprocessing import RollingFeatures
from skforecast.model_selection import backtesting_forecaster, TimeSeriesFold
# 1. Load and prepare data (MUST have DatetimeIndex with frequency)
data = pd.read_csv('data.csv', index_col='date', parse_dates=True)
data = data.asfreq('h') # Set frequency — required
# 2. Train/test split (time-based, never random)
end_train = '2023-01-01'
y_train = data.loc[:end_train, 'target']
y_test = data.loc[end_train:, 'target']
# 3. Create forecaster with optional rolling features
rolling_features = RollingFeatures(
stats=['mean', 'std'],
window_sizes=24
)
forecaster = ForecasterRecursive(
estimator=RandomForestRegressor(n_estimators=100, random_state=123),
lags=24,
window_features=rolling_features,
transformer_y=None, # e.g., StandardScaler() for scaling
categorical_features='auto', # Auto-detect and encode non-numeric exog columns
differentiation=None, # e.g., 1 for first-order differencing
dropna_from_series=False, # True to drop NaN rows; False to keep (NaN-tolerant estimators)
)
# 4. Train
forecaster.fit(y=y_train)
# 5. Predict
predictions = forecaster.predict(steps=10)
# 6. Backtesting (proper evaluation)
cv = TimeSeriesFold(
steps=10,
initial_train_size=len(y_train),
refit=False,
fixed_train_size=False,
)
metric, predictions_bt = backtesting_forecaster(
forecaster=forecaster,
y=data['target'],
cv=cv,
metric='mean_absolute_error',
)
print(f"MAE: {metric}")
# 7. Prediction intervals
# Default interval is [0.05, 0.95] (90%). Here [0.1, 0.9] creates an 80% interval.
forecaster.fit(y=y_train, store_in_sample_residuals=True)
predictions_interval = forecaster.predict_interval(
steps=10,
interval=[0.1, 0.9], # 80% prediction interval (quantiles, 0-1 scale)
method='bootstrapping',
n_boot=500,
)
# Exogenous variables must cover the forecast horizon during prediction
forecaster = ForecasterRecursive(
estimator=RandomForestRegressor(n_estimators=100, random_state=123),
lags=24,
)
forecaster.fit(y=y_train, exog=exog_train)
predictions = forecaster.predict(steps=10, exog=exog_test)
from skforecast.direct import ForecasterDirect
# Must specify `steps` at creation — trains one model per step
forecaster = ForecasterDirect(
estimator=RandomForestRegressor(n_estimators=100, random_state=123),
lags=24,
steps=10,
categorical_features='auto', # Auto-detect and encode non-numeric exog columns
)
forecaster.fit(y=y_train, exog=exog_train)
predictions = forecaster.predict(exog=exog_test)
data.asfreq('h') (or 'D', 'MS', etc.).dropna_from_series=True to drop incomplete rows, or keep dropna_from_series=False (default) with NaN-tolerant estimators (LightGBM, CatBoost, HistGradientBoosting, XGBoost hist). Alternatively, impute missing values first.predict() must have rows for every future step.store_in_sample_residuals=True: Required before calling predict_interval() with method='bootstrapping' on a standalone forecaster. During backtesting, residuals are computed automatically.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
17 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.
/backtesting-configurationConfigures TimeSeriesFold parameters for backtesting based on deployment scenarios. Maps business requirements (retraining frequency, forecast horizon, data budget) to cross-validation strategy parameters. Use when the user describes how they plan to deploy or evaluate a model.
/baseline-forecasting/skforecast:forecasting-single-seriesfrom skforecast
npx claudepluginhub skforecast/skforecast --plugin skforecastOther plugins' skills for the same job