3

I am trying to use GammaRegressor to predict the customer revenue in the next 3 months, 6 months etc.

So, I tried using the GammaRegressor based on suggestions from the posts here.

My Y variable ranges from 0 to 6172000.9368

However, when I passed in my data, I got the below error

GammaRegressor model failed to execute Some value(s) of y are out of the valid range of the loss 'HalfGammaLoss'.

When I researched online, I came across this github link here which has code snippet in line 227, 228 about value error.

So, not sure what is causing this issue?

The Great
  • 3,272

1 Answers1

5

Zero is not a valid value for a gamma distribution. The PDF has the gamma function in the denominator of a fraction. However:

$$ \underset{x\rightarrow 0^+}{\lim}\Gamma(x)=\infty $$

This error message is alerting you to the fact that you have a value that cannot occur according to the assumed distribution.

Dave
  • 62,186
  • So, we should make only predictions for customers who have revenue above 0? but in real time, there might be customers who have 0 revenue in certain look back period but we wish to predict for them (even if it is going to zero). Does adding values like 0.1 to 0 is okay? – The Great Nov 21 '22 at 13:30
  • Because I don't wish to avoid this customers. So then only option is tweedie? which goes from P=1 to P=2 inverse gamma etc? – The Great Nov 21 '22 at 13:31
  • 2
    @TheGreat You can use square loss with a $\log$ link. There might be better loss functions and link functions for your work, but square loss with a $\log$ link could be fine, too. – Dave Nov 21 '22 at 13:43
  • Thanks, I referred your other post. So, I thought loss function is like a hyperparamter thay we can change but looks like scikit-learm doesn't have that here. https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.GammaRegressor.html – The Great Nov 22 '22 at 00:23
  • Earlier, I used an AutoML solution which I giess had halfgamma loss as input. So, not sure how do we modify it? – The Great Nov 22 '22 at 00:27
  • @TheGreat What do you want to modify? – Dave Nov 22 '22 at 00:40
  • How do we change fron half gamma loss to square loss? – The Great Nov 23 '22 at 10:41