1
$\begingroup$

I am using Random Forest Regressor to predict inventory needs. The data I am using to train the model lists the total quantity picked for each product per date, but does not include rows where total quantity picked for a product on the specified date is 0. The model considers the features that allow it to take date into consideration. For details on the data being used see the example data below:

                 UPC  day_ID  month    day_of_year  day_of_week  quantity_picked
0      0000000002554  7500.0      5            141            1              4.0
1      0000000002554  7503.0      5            144            4              2.0
2      0000000002554  7512.0      6            153            6              2.0
3      0000000002554  7527.0      6            168            9              2.0
4      0000000003082  7494.0      5            135            2              2.0
5      0000000003082  7495.0      5            136            3              2.0
6      0000000003082  7496.0      5            137            4              8.0
7      0000000003082  7497.0      5            138            5              4.0
8      0000000003082  7498.0      5            139            6              4.0
9      0000000003082  7499.0      5            140            0              9.0
10     0000000003082  7500.0      5            141            1              3.0
11     0000000003082  7501.0      5            142            2              5.0
12     0000000003082  7502.0      5            143            3              3.0
13     0000000003082  7503.0      5            144            4              8.0
14     0000000003082  7505.0      5            146            6              2.0
15     0000000003082  7506.0      5            147            3              7.0

Will the model be less accurate at predicting inventory needs because it is missing dates for items where quantity picked is 0? I have tried running the same model with the rows where quantity picked = 0 but the total number of rows changes from approximately 50k to 5 million and my computer literally can't handle it, it just freezes. Without the rows where quantity picked = 0, the model reports mean squared log error level of .39448 and runs successfully within 4 minutes 37 seconds.

Any guidance on if that data is necessary or not would be very much appreciated and/or advice on how to improve performance/accuracy of such a model.

$\endgroup$

1 Answer 1

0
$\begingroup$

A random forest trained on data whose labels are all positive integers cannot produce any prediction less than 1. So yes, the model will be less accurate.

I would suggest including a random subset of the rows with 0 sold, so that the forest can learn a (hopefully representative) pattern to them. I'd also probably weight them higher in the fitting algorithm, to reproduce a more faithful average of items sold (in each leaf).

$\endgroup$
4
  • $\begingroup$ Thank you for the advice. How large of a random subset of the rows with 0 sold would you suggest? Also, any advice on how to go about weighting them higher in the fitting algorithm or any resources you can suggest with examples on how to do so? $\endgroup$
    – Emily Reed
    Jul 10, 2019 at 13:16
  • $\begingroup$ Also, are there any models where this wouldn't be an issue? $\endgroup$
    – Emily Reed
    Jul 10, 2019 at 13:41
  • $\begingroup$ Use as many 0-rows as your computer will deal with in a reasonable amount of time, but I'd probably start with 20-50k (to roughly match the number of other entries). In sklearn, the random forest's fit has an optional parameter sample_weight, an array-like of weights; probably easiest to define a Series based on the quantity_picked column of your dataframe, perhaps just a lambda, with weights 1 for positive-sold and 100 for none-sold (if you're taking about 1/100 of the original 0-rows). $\endgroup$
    – Ben Reiniger
    Jul 10, 2019 at 14:09
  • $\begingroup$ All(?) models will suffer some bias without the 0-rows, but e.g. linear regression could predict values below 1. If there's a strong trend, say Wednesdays sell 10 and Thursdays sell 20 and Fridays sell 30, a linear regression would predict Tuesdays sell 0 (and Mondays sell -1 !). KNN would fail to predict anything less than 1, but SVM and NN could predict outside the training range (though probably not with great accuracy). $\endgroup$
    – Ben Reiniger
    Jul 10, 2019 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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