You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question or bug report about lags and a global model using MLForecast.
My expectation is that in a global model, the results should be identical whether predicting an individual time series or multiple time series, as long as all features are provided correctly and consistently.
However, when I use the lags feature, the forecast for an individual time series (e.g., one time series) differs from predicting the same time series together with multiple other time series.
Versions / Dependencies
mlforecast 0.15.0
Reproduction script
importpandasaspdimportnumpyasnpfrommlforecastimportMLForecastfromsklearn.ensembleimportRandomForestRegressorprint("# Create data")
defcreate_data():
np.random.seed(42)
data= []
forts_idinrange(3): # Drei Zeitreihenfortinrange(30):
data.append({
'unique_id': f'ts_{ts_id}',
'ds': t,
'y': np.sin(t/5) +ts_id+np.random.normal(0, 0.1)
})
returnpd.DataFrame(data)
df=create_data()
print("# single time series")
df_single=df[df['unique_id'] =='ts_0']
print("# lag features")
lags= [1, 2, 3]
print("# mlforecast model with RandomForestRegressor")
forecast=MLForecast(
models=RandomForestRegressor(),
freq=1,
lags=lags
)
print("# Prediction single time series")
forecast.fit(df_single, id_col='unique_id', time_col='ds', target_col='y')
single_forecast=forecast.predict(5) # 5 Zeitschritte vorhersagenprint("# prediction multiple time series")
forecast.fit(df, id_col='unique_id', time_col='ds', target_col='y')
multi_forecast=forecast.predict(5)
print("# filter single time series from multiple time series")
multi_forecast_single=multi_forecast[multi_forecast['unique_id'] =='ts_0']
print("# results comparison")
print("Single Time Series Forecast:")
print(single_forecast)
print("\nSame Time Series Forecast (with others):")
print(multi_forecast_single)
single_forecastprint("# difference between forecasts")
difference=single_forecast.set_index('ds')['RandomForestRegressor'] -multi_forecast_single.set_index('ds')['RandomForestRegressor']
print("\nDifference between forecasts:")
print(difference)
Issue Severity
Medium: It is a significant difficulty but I can work around it.
The text was updated successfully, but these errors were encountered:
Hey. You're not "predicting" one or many series, you're training a model with different datasets, so it's expected to produce different results. If you're interested in training one model per serie you can use statsforecast.
What happened + What you expected to happen
Thank you for your fantastic library.
I have a question or bug report about lags and a global model using MLForecast.
My expectation is that in a global model, the results should be identical whether predicting an individual time series or multiple time series, as long as all features are provided correctly and consistently.
However, when I use the lags feature, the forecast for an individual time series (e.g., one time series) differs from predicting the same time series together with multiple other time series.
Versions / Dependencies
mlforecast 0.15.0
Reproduction script
Issue Severity
Medium: It is a significant difficulty but I can work around it.
The text was updated successfully, but these errors were encountered: