In this lab, you'll learn how to generate random normal distributions in Python. You'll learn how to visualize a histogram and build a density function using the formula.
You will be able to:
- Use
numpy
to generate a random normal distribution - Calculate the density function for normal distributions with a Python function
- Plot and interpret density plots and comment on the shape of the plot
Here's the formula for the normal distribution density function once more:
Here,
-
$\mu$ is the mean -
$\sigma$ is the standard deviation $\pi \approx 3.14159 $ - $ e \approx 2.71828 $
# Generate a random normal variable with given parameters , n=5000
Make sure to get the bin positions and counts for each of the obtained bins. You can use official documentation to view input and output options for plt.hist()
# Calculate a histogram for above data distribution
Use the formula to calculate the density function with $\mu$ , $\sigma$ and bin information obtained before
# Calculate the normal Density function
density = None
# Plot histogram along with the density function
# Use seaborn to plot the histogram with KDE
In this lab, you learned how to generate random normal distributions in Python using Numpy. You also calculated the density for normal distributions using the general formula as well as seaborn's KDE. Next, you'll move on to learn about the standard normal distribution and how normal distributions are used to answer analytical questions.