# Fitting a Poisson regression

Continuing with the `crab`

dataset you will fit your first Poisson regression model in this exercise.

The `crab`

dataset has been preloaded in the workspace.

This is a part of the course

## “Generalized Linear Models in Python”

### Exercise instructions

- Import
`statsmodels.api`

library as`sm`

. - Import
`glm`

from`statsmodels.formula.api`

. - Using
`Poisson()`

for the response distribution fit the Poisson regression with`sat`

as the response and`weight`

for the explanatory variable. - Display the model results using
`.summary()`

.

### Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

```
# Import libraries
import ____.____ as sm
from ____.formula.api import ____
# Fit Poisson regression of sat by weight
model = ____('____ ~ ____', data = ____, family = ____.____.____).____
# Display model results
____(model.____)
```

This exercise is part of the course

## Generalized Linear Models in Python

Extend your regression toolbox with the logistic and Poisson models and learn to train, understand, and validate them, as well as to make predictions.

Here you'll learn about Poisson regression, including the discussion on count data, Poisson distribution and the interpretation of the model fit. You'll also learn how to overcome problems with overdispersion. Finally, you'll get hands-on experience with the process of model visualization.

Exercise 1: Count data and Poisson distributionExercise 2: Visualize the responseExercise 3: Fitting a Poisson regressionExercise 4: Interpreting model fitExercise 5: Estimate parameter lambdaExercise 6: Interpret Poisson coefficientsExercise 7: Poisson confidence intervalsExercise 8: The Problem of OverdispersionExercise 9: Is the mean equal to the variance?Exercise 10: Computing expected number of countsExercise 11: Checking for overdispersionExercise 12: Fitting negative binomialExercise 13: Confidence intervals for negative Binomial modelExercise 14: Plotting a regression modelExercise 15: Plotting data and linear model fitExercise 16: Plotting fitted values### What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.