Hi team, I have a dataframe where there are 4 colu...
# mlforecast
p
Hi team, I have a dataframe where there are 4 columns. - "unique_id", "ds", "feat1", "y". The feature "feat1" is variable & is a defined value based on the item & date (for each current or future date & for a given item/unique_id, feat1 will have some value b/w 1 to n). I tried fitting & predicting but getting an error. Can someone please help me with this? For this test setup, the dataframe has a single item or time-series (all unique_ids are same)
# train has columns as - [unique_id, ds, feat1, y]
fcst.fit(train,
dropna=True,
static_features=['feat1'],
)
predictions = fcst.predict(h=12, X_df=test[['unique_id', 'ds', 'feat1']])
Error -
```ValueError: The following features were provided through
X_df
but were considered as static during fit: ['feat1'].
Please re-run the fit step using the
static_features
argument to indicate which features are static. If all your features are dynamic please pass an empty list (static_features=[]).```
j
If
feat1
changes over time then it isn't a static feature, you should set
static_features=[]
as the message suggests
p
Hi Jose. Thanks for replying. I meant for a given
unique_id
&
ds
, there will be a particular value for
feat1
in both train & test data.
j
Ah, ok. In that case you don't need to provide the
X_df
argument to predict, the static features are handled automatically
p
But while predicting the demand for future dates, how the model will get the information about this additional feature for the future dates for a given unique_id. For eg., if I'm fitting the mlforecast model like below:
fcst.fit(train,
dropna=True,
static_features=['promo_flag'],
)
we're providing the additional features as static_features. So for the same unique_ids, & for future dates, we need to provide the values for
feat1
as well. Isn't it?
j
Oh sorry, I thought the message said the value for feat1 was fixed for the same id. If it changes over time then as my first message says it isn't a static feature (it's dynamic) and you should provide an empty list as static features so that they're interpreted as dynamic and the future values (provided through X_df) are used
p
Ohh my bad. As the name says static. I shouldn't provide
feat1
in the static_features. But when I'm doing
.predict
with
h
&
X_df
as its input where
X_Df
has 3 columns
unique_id
,
ds
&
feat1
then it is giving me predicted values for
y
but the output df doesn't contain the
feat1
column which it should as per this use case. Any suggestions on this Jose?
j
The features aren't returned by default, but you can use a callback to save them and extract them afterwards (guide)
👍 1
p
Just to provide you more context, say there is a demand forecasting problem where there is unique_id, ds, item_price & y. The demand depends both on datetime features & item_price. This
feat1
can be something like item_price. So while forecasting for future dates, I wanted to include that what will be the item_prices for the given unique_id & for each of those future dates for which I'm predicting the
y
j
I think that's exactly what is done here
p
got it. Thanks a lot Jose for the help. With the callback, I'm getting the actual df with
feat1
which is being used for forecasting for future dates. Thanks a lot.
j
If you need to match the ids and dates with that you can use the make_future_dataframe method of MLForecast
👍 1