0
$\begingroup$

I have trained xgboost algorithm to predict the number of items sale on a given day and got pretty good results, now I would like to forecast sales ahead of one week.

I tried re-training the algorithm by adding date as one of the independent variables, however, got an exception on date type.

So can someone please suggest how to predict forecast item sales count next one week.

In-sample predictions code:

train_x,X_test,train_y,y_test=train_test_split(data,data_y,
                                               test_size=0.30)
xgb = xgboost.XGBRegressor(n_estimators=100, learning_rate=0.08, gamma=0, subsample=0.75,
     colsample_bytree=1, max_depth=7)
xgb.fit(train_x,train_y)
predictions = xgb.predict(X_test)
$\endgroup$
  • $\begingroup$ do you have any code to show? $\endgroup$ – oW_ Jul 19 '19 at 20:40
  • $\begingroup$ @oW_, Nope, have coded for in-sample predictions, need guidance on out-sample predictions. Added in-sample code in question summary $\endgroup$ – Optimizor Jul 20 '19 at 11:24
1
$\begingroup$

Yes, you cannot pass in a datetime object as a feature to XGboost Regressor, because it isn't time-series forecasting tool such as ARIMA.

Instead, you create various features from the timeseries object such as year, month, day of month, day of week, number of days until public holiday etc. All of these are of type int. Drop the timeseries column.

When you're passing in the test data, you convert the datetime object into the above features.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Sid, have done similar kind of trick but with lagged features.It worked for in-sample predictions. Am having trouble in out of sample predictions. $\endgroup$ – Optimizor Jul 21 '19 at 7:08
  • $\begingroup$ It probably treated it as a categorical feature $\endgroup$ – Sid Jul 21 '19 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.