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:
- Generate random normal distributions in python with given parameters
- Calculate the density function for normal distributions
- Use seaborn to visualize distributions with histograms and density functions
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
<matplotlib.axes._subplots.AxesSubplot at 0x1a121adac8>
In this lab, you learned how to generate random normal distributions in Python using Numpy. You also calculated the density for gaussian distributions using the general formula as well as seaborn's kde. Next, you'll move on an learn how normal distributions are used to answer analytical questions.