I am training an ML model on multiple unique ids, ...
# mlforecast
s
I am training an ML model on multiple unique ids, but when i am trying to forecast, i am trying to forecast for one unique_id only because forecast horizon is different for each unique id & there are external regressors data also in it.. hence i tried something like this when generating forecast # Create a dataframe with data for only the ID you want to forecast single_id_df = df[df['unique_id'] == 'specific_id'] # Generate forecasts forecasts = fcst.predict(h= horizon, X_df =single_id_df) However, i am getting following error..
Copy code
ValueError: Found missing inputs in X_df. It should have one row per id and time for the complete forecasting horizon.
You can get the expected structure by running `MLForecast.make_future_dataframe(h)` or get the missing combinatins in your current `X_df` by running `MLForecast.get_missing_future(h, X_df)`.
I even checked X_df for any missing inputs, it has no missing inputs & length of X_df is same as h.. Why i am getting this error, can anyone pls help..
j
It expects all ids to be present. Can you try setting
ids=['specific_id']
in the predict call?
s
tried, it is still giving same error 😞
j
The following works as expected:
Copy code
from mlforecast import MLForecast
from sklearn.linear_model import LinearRegression
from utilsforecast.data import generate_series
from utilsforecast.feature_engineering import trend

freq = 'D'
h = 5
data = generate_series(10, freq=freq)
train, future = trend(data, freq=freq, h=h)
fcst = MLForecast(models=[LinearRegression()], freq=freq)
fcst.fit(train, static_features=[])
fcst.predict(h=h, X_df=future, ids=[0])
You must truly have missing combinations for that id
s
fcst.get_missing_future(h=h, X_df=X1_df) I used this to check for missing data, i got None as answer.. I checked X_df.isna().sum(). Still no null values in X_df..
j
If you can provide a reproducible example I can help further. The example I provided works
s
Hi @José Morales, you are correct.. there looks to be issue with that id.. other ids are working..only that id is not working..
thanks a lot.. But issue with that id persists.. will figure out issue with that id
j
Keep in mind that not only the shape matters but the times. If there are missing times for that id you'll get an error, the times have to be consecutive
✅ 1
s
you are again bang on! There were few missing dates, hence those ids were giving error.. thanks again