Get Started

Generating and plotting Poisson distributions

In the previous exercise, you calculated some probabilities. Now let's plot that distribution.

Recall that on a certain highway turn, there are 2 accidents per day on average. Assuming the number of accidents per day can be modeled as a Poisson random variable, let's plot the distribution.

This is a part of the course

“Foundations of Probability in Python”

View Course

Exercise instructions

  • Import poisson from scipy.stats, matplotlib.pyplot as plt, and seaborn as sns.
  • Generate a Poisson distribution sample with size=10000 and mu=2.
  • Plot the sample generated.

Hands-on interactive exercise

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

# Import poisson, matplotlib.pyplot, and seaborn
from ____ import ____
import ____ as ____ 
import ____ as ____

# Create the sample
sample = poisson.___(mu=____, size=10000, random_state=13)

# Plot the sample
sns.distplot(____, kde=False)
plt.show()

This exercise is part of the course

Foundations of Probability in Python

IntermediateSkill Level
4.0+
1 reviews

Learn fundamental probability concepts like random variables, mean and variance, probability distributions, and conditional probabilities.

Until now we've been working with binomial distributions, but there are many probability distributions a random variable can take. In this chapter we'll introduce three more that are related to the binomial distribution: the normal, Poisson, and geometric distributions.

Exercise 1: Normal distributionsExercise 2: Range of valuesExercise 3: Plotting normal distributionsExercise 4: Within three standard deviationsExercise 5: Normal probabilitiesExercise 6: Restaurant spending exampleExercise 7: Smartphone battery exampleExercise 8: Adults' heights exampleExercise 9: Poisson distributionsExercise 10: ATM exampleExercise 11: Highway accidents exampleExercise 12: Generating and plotting Poisson distributions
Exercise 13: Geometric distributionsExercise 14: Catching salmon exampleExercise 15: Free throws exampleExercise 16: Generating and plotting geometric distributions

What is DataCamp?

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

Start Learning for Free