Skforecast
raw JSON → 0.22.0 verified Mon Apr 27 auth: no python
Skforecast is a Python library for time series forecasting using statistical and machine learning models. It works with any estimator compatible with the scikit-learn API, including LightGBM, XGBoost, CatBoost, Keras, and many others. Current version is 0.22.0, with a release cadence of roughly quarterly.
pip install skforecast Common errors
error ImportError: cannot import name 'grid_search_forecaster' from 'skforecast.model_selection' ↓
cause In v0.22.0, the model_selection module was refactored; `grid_search_forecaster` function was removed.
fix
Use
from skforecast.model_selection import BacktestGridSearch instead. See docs: https://skforecast.org/0.22.0/api/model_selection error ValueError: The length of the values (1) does not match the length of the index (100) ↓
cause When using `ForecasterAutoregCustom`, the custom `create_lags` function returns an array with wrong shape (e.g., one column instead of multiple lags).
fix
Ensure
create_lags returns a NumPy array of shape (n_samples, n_lags). error AttributeError: 'ForecasterAutoreg' object has no attribute 'predict_interval' ↓
cause `predict_interval` was removed in v0.22.0; interval prediction is now done via `predict` with `interval=True`.
fix
Use
forecaster.predict(steps=5, interval=True). Warnings
breaking In v0.22.0, model_selection module was reorganized. Functions like `grid_search_forecaster` and `random_search_forecaster` are removed. Use `BacktestGridSearch` and `BacktestRandomSearch` instead. ↓
fix Replace `from skforecast.model_selection import grid_search_forecaster` with `from skforecast.model_selection import BacktestGridSearch` and adjust usage.
breaking In v0.21.0, `TimeSeriesDifferentiator` moved from `skforecast.utils` to `skforecast.preprocessing`. Old import will raise ImportError. ↓
fix Change import to `from skforecast.preprocessing import TimeSeriesDifferentiator`.
deprecated `ForecasterAutoregDirect` is deprecated in favor of `ForecasterAutoregMultiOutput` since v0.12.0. ↓
fix Use `ForecasterAutoregMultiOutput` with steps parameter.
gotcha When using `ForecasterAutoregCustom`, the custom `create_lags` function must return a numpy array of shape (len(y), len(lags)). Wrong shape leads to silent errors. ↓
fix Ensure function returns array with correct dimensions; test with a small dataset first.
gotcha `ForecasterAutoreg.fit()` expects `y` as a pandas Series. Passing a numpy array or DataFrame with multiple columns will raise ValueError. ↓
fix Always convert to pd.Series: `y = pd.Series(y_array)`.
deprecated `ForecasterAutoreg` parameter `selector_step` is deprecated since v0.18.0. Use `feature_selection` argument in `fit()` instead. ↓
fix Remove `selector_step` and pass `feature_selection=True` to `fit()`.
Imports
- ForecasterAutoreg wrong
from skforecast.ForecasterAutoreg import ...correctfrom skforecast.recursive import ForecasterAutoreg - ForecasterAutoregDirect wrong
from skforecast.ForecasterAutoregDirect import ...correctfrom skforecast.direct import ForecasterAutoregDirect - ForecasterAutoregCustom
from skforecast.recursive import ForecasterAutoregCustom - ForecasterAutoregMultiOutput
from skforecast.recursive import ForecasterAutoregMultiOutput - ForecasterSARIMAX
from skforecast.sarimax import ForecasterSARIMAX - BacktestGridSearch wrong
from skforecast.model_selection_grid_search import ...correctfrom skforecast.model_selection import BacktestGridSearch - BacktestRandomSearch
from skforecast.model_selection import BacktestRandomSearch - TimeSeriesDifferentiator wrong
from skforecast.utils import TimeSeriesDifferentiatorcorrectfrom skforecast.preprocessing import TimeSeriesDifferentiator
Quickstart
import numpy as np
import pandas as pd
from skforecast.recursive import ForecasterAutoreg
from sklearn.ensemble import RandomForestRegressor
# Example data
y = pd.Series(np.random.rand(100), index=pd.date_range(start='2020-01-01', periods=100, freq='D'))
# Create forecaster
forecaster = ForecasterAutoreg(
regressor=RandomForestRegressor(random_state=123),
lags=10
)
# Fit
forecaster.fit(y=y)
# Predict
predictions = forecaster.predict(steps=5)
print(predictions.head())