In this lab we shall learn how to generate random normal distributions in python. We shall look into visualising a histogram and building a density function using the formula as well as seaborn's built in functions.
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 calculating normal distribution density function.
# Generate a random normal variable with given parameters , n=5000
Refer to official documentation to view input and output options for plt.hist()
# Calculate a histogram for above data distribution
Calculate the density function (using above formula) with mu, sigma and bin information calculated above .
# Calculate the normal Density function
density = None
# Plot histogram along with the density function
<matplotlib.axes._subplots.AxesSubplot at 0x1a19d4cda0>
In this lab we saw how to generate random normal distributions in python using numpy. We also looked into calculating the density for gaussian distributions using the general formula as well as seaborn's kde. We shall now move on to see how we can analyze such variables for answering analytical questions.