https://github.com/nixtla logo
l

Luis Enrique Patiño

08/01/2023, 6:34 PM
Hi everyone, I have a problem while running the ML forecast CV. This is my MLForecast constructor:
# Instantiate the MLForecast object
mlf = MLForecast(
models={
'LGBM': LGBMRegressor(),
'XGB' : XGBRegressor(),
'XGB_hiper' : XGBRegressor(),
'LR' : LinearRegression(),
'avg' : LGBMRegressor(**lgb_params),
'q75' : LGBMRegressor(**lgb_params, objective='quantile', alpha=0.75),
'q25': lgb.LGBMRegressor(**lgb_params, objective='quantile', alpha=0.25)
},
freq='W-SUN',  # Frequency of the data
lags=[1, 2, 52],  # Specific lags to use as regressors
lag_transforms = {
1: [expanding_mean],
1: [(rolling_mean, 3)],
1: [(ewm_mean, 0.5)],
1: [increment_with_previous],
52: [increment_with_previous],
52: [(rolling_mean, 3)]
},
target_transforms=[StandardScaler()],
date_features = ['year', 'month', 'quarter', 'week', 'is_month_start', 'is_month_end'],  # Date features to use as regressors
)
static_features = ['holiday']
mlf.fit(train, static_features=static_features)
And when I run the cv
y_pred_cv_mlf = mlf.cross_validation(
train.drop('holiday', axis=1),
window_size=h,
n_windows=2,
step_size=1
)
I get this error: ValueError: Cross validation result produced less results than expected. Please verify that the frequency set on the MLForecast constructor matches your series' and that there aren't any missing periods.
m

Max (Nixtla)

08/02/2023, 5:36 AM
It seems you are encountering an issue with time series cross validation when using the MLForecast library. The error message suggests that the cross-validation operation resulted in fewer results than expected, indicating a potential discrepancy between the frequency of your time series data and the frequency set in the MLForecast constructor [(1)](https://nixtla.github.io/mlforecast/forecast.html) .
Please tell us if this helps you: @José Morales can maybe help 🙂
j

José Morales

08/03/2023, 12:54 AM
It can be one of three cases: • You defined W-SUN as frequency but your data has W-TUE for example. • You have gaps in your series, for example your data jumps from 2023-07-09 to 2023-07-23 (it skipped 2023-07-16) • One or more of your series are too short for the cv. For example if your horizon is 10 and you have two windows you need at least 21 samples in each serie
l

Luis Enrique Patiño

08/03/2023, 7:10 PM
Hi, José hit the jackpot. We had 2 series from 2020-2022, while all of the series are from 2020-2023. Removing these series fixed everything. Thanks!!
👍 1
2 Views