New to pyro - Looking for Poisson GLM example


I’m finding it hard to find a tutorial on how to run a simple poisson GLM. I’m working with insurance data and do not have the time for STAN to sample at such a slow pace. I’m hoping pyro with my GPU will allow for a faster fit.

I found some videos on pyro in general but this particular problem seems to elude me. I’m not sure if it helps, but below is the stan code.

data {int<lower=0> N;
        vector[N] EDIT_9644A;
	vector[N] credit_score_2;
	vector[N] gf;
	vector[N] credit_spline;
        int<lower=0> y1[N];

parameters {
    real EDIT_9644A_coeff; 
    real credit_score_2_coeff;
    real gf_coeff;
    real credit_spline_coeff ;   
    real intercept;        
model {
    EDIT_9644A_coeff ~ normal(0, 1);  
    credit_score_2_coeff ~ normal(0, 1);
    gf_coeff ~ normal(0, 1);
    credit_spline_coeff ~ normal(0, 1);
    intercept ~ normal(0,5);

    y1 ~ poisson_log(EDIT_9644A_coeff*EDIT_9644A +
credit_score_2_coeff*credit_score_2 +
gf_coeff*gf +

Thanks for any help or site someone can point me to.

Hi @jordan.howell2, I’d recommend starting with the Bayesian regression tutorial and changing the likelihood from Normal to Poission:

- sigma = pyro.sample("sigma", dist.Uniform(0., 10.))
- mean = self.linear(x).squeeze(-1)
- pyro.sample("obs", dist.Normal(mean, sigma), obs=y)
+ rate = self.linear(x).squeeze(-1).exp()
+ pyro.sample("obs", dist.Poisson(rate), obs=y)

If .exp() gives you NANs you might alternatively try torch.nn.functional.softplus(-) as the nonlinearity.

1 Like

Thanks. Should I change the observed value y to the log form since a frequentist model uses a log link for Poisson distros?

The Poisson distribution expects obs to be in count units, so IIUC your y will remain unchanged and your log link function would correspond to the .exp() in rate = log_rate.exp().

1 Like