Garve / scikit-bonus

scikit-learn extensions that I find useful.
BSD 3-Clause "New" or "Revised" License
12 stars 2 forks source link

may you share links to theory behind this code :punish overestimations by the model 5 times #6

Closed Sandy4321 closed 1 year ago

Sandy4321 commented 1 year ago

great code thanks onoy punish overestimations by the model 5 times Garve/scikit-bonus: scikit-learn extensions that I find useful.

may you share links to theory behind this code or just create some blog post pls?

Garve commented 1 year ago

Hi Sandy!

There is no real theory behind this. It's just if you want to treat over- or underestimates differently, which might be the case if you plan capacities, for example. Having too much capacity for something might be bad because you waste too many resources, but having not enough capacity for something might be even worse.

Best Robert

Sandy4321 commented 1 year ago

What capacity is? Do you have some description for algorithm you use

Garve commented 1 year ago

Let's assume that you work in as company that sells furniture. Now it is your job to forecast how many chairs you will sell using some model. Somebody from your company will use your model to produce the chairs and store them in a warehouse. If your model says that you will sell x chairs on a day, there will be x chairs on the warehouse.

So you build a model, and of course, it is not perfect. Sometimes you predict too much, sometimes you predict not enough. If you overestimate the number of chair sales, e.g. your model says 1000 chairs, but actually you only sold 800 chairs, 200 chairs have to stay in your warehouse. This is bad because they take up space, which costs money.

If you underestimate the number, e.g. the model says 500 chairs, but actually you sold 600 chairs, then you couldn't sell 100 chairs, which means less revenue and a lot of unhappy customers. And this is much much worse then overestimating the number. If your model would have told you 700, you would still have 100 chairs in your warehouse, but at least every customer would have been happy and you would have sold 600 chairs instead of 500.

That's way it makes sense to say: if your model says 700 instead of 600, the loss should be smaller that if the model says 500 instead of 600. Or in short: overestimating is better than underestimating.

And for this, you cannot use linear regression, for example, because its loss function punished both cases in the same way (y - y_predict)².

In my version here, I added two coefficients, one that appears when overestimating, one that appears when underestimating. For example, if you overestimate, the loss is 2(y - y_predict)². If you underestimate, it's 5(y - y_predict)².

The rest of the algorithm is like linear regression, just with this adjusted loss function.

Does this help?

Best Robert

Sandy4321 commented 1 year ago

Just great, thanks