Imagine following use case. We want to predict the demand for food and drinks in a restaurant. After visualizing the target drinks in liter and food in pieces we can clearly see a trend in the dataset. On weekend the restaurant serves much more foods and drinks than on weekdays. The restaurant has a nice garden to sit, so the amount of customers is higher in summer month than in winter.

So it would be good to has some date or time specific features for our model. Our models are the Random Forest and LightGBM. LightGBM has the ability to use categorical features such as weekday with the values 'Monday', 'Thuesday' and so on. For the random forest I have two options. Create a feature weekday as an integer between 1 and 7 or make an one-hot-encoding (7 new columns or features with binary values). We can do the same with the month.

But what should we do with the day of month or the year? The dataset contains the last 5 years, so a one hot encoding would work. If I want to one hot encode the day of month I need 31 new columns with boolean values.

I found a few examples for feature generation in such a scenario and can´t find a general approach. Some of the use the one-hot-encoding, others make time series features as integers (for example day of month).

Me as a newby in demand forecast and ML thinks the number 12 (=December) is 12 times higher as the 1 (=January), so we have to one-hot-encode it because in reality the demand in december is nearly similar to the demand in january. So using an integer as month feature would confuse my model. Speaking in terms of the random forest, is this necessary at all?

Or has our model the ability to learn this from the data?


Your Answer

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

Browse other questions tagged or ask your own question.