6
$\begingroup$

I want to predict count data. In my understanding both standard classification and regression are not well suited for this. A poisson or binomial regression algorithm seems to do the trick.

I am used to doing most of my ML tasks in sklearn. But on this topic I could not find an implementation. Are there any suitable options within the python universe for this?

$\endgroup$
8
$\begingroup$

Not quite sklearn but have you tried xgboost?

The XGBRegressor in xgboost accepts many different objective functions including poisson count:poisson for count data.

It also plays nicely with sklearn so can be used with grid search, pipelines etc.

| improve this answer | |
$\endgroup$
  • $\begingroup$ This sounds promising - I will give it a try - though I am not sure when I will have time for this ;). $\endgroup$ – El Burro Oct 15 '18 at 6:46
  • $\begingroup$ Sorry for the late reply - i think while interesting as an objective functions this is not what I am looking for. I am looking for a regressor that predictions only return integers - and at least when I tried this one it did not do that. $\endgroup$ – El Burro Aug 2 '19 at 14:32
5
$\begingroup$

statsmodels has you covered.

There aren't a lot of great examples of Poisson regression in the statsmodels API, but if you're happy with GLMs, statsmodels has a GLM API which lets you specify any single-parameter distribution, including Poisson.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Do you know of any non-linear models that support poisson regression or other methods to predict count data? $\endgroup$ – El Burro Sep 20 '17 at 8:06
  • $\begingroup$ Can you clarify what you mean by "non-linear" in this context? $\endgroup$ – R Hill Sep 20 '17 at 16:06
  • $\begingroup$ Like a neural network, some of the many variants of decision trees, suport vector machines etc. $\endgroup$ – El Burro Sep 20 '17 at 16:16
  • 2
    $\begingroup$ Okay. Well, regular Poisson regression is the parameterisation of a Poisson distribution by a linear combination of your predictor variables, so you could replace that linear combination by any non-linear transformation you like. So you could produce a neural network, the output layer of which is a point estimate of a Poisson process. This would, however, be a lot more complicated than regular GLM Poisson regression, and a lot harder to diagnose or interpret. It's probably worth trying a standard Poisson regression first to see if that suits your needs. $\endgroup$ – R Hill Sep 20 '17 at 16:23
  • 1
    $\begingroup$ You probably need to write down a loss function which is equal to the negative log likehood of the poisson distribution. $\endgroup$ – Kota Mori Nov 14 '18 at 22:56
0
$\begingroup$

Scikit-learn v0.23 now has PoissonRegressor:

https://scikit-learn.org/0.23/auto_examples/release_highlights/plot_release_highlights_0_23_0.html#generalized-linear-models-and-poisson-loss-for-gradient-boosting

| improve this answer | |
$\endgroup$

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.