Complete the code to import the SciPy stats module.
from scipy import [1]
The stats module in SciPy provides statistical functions and distributions.
Complete the code to create a normal distribution object with mean 0 and standard deviation 1.
dist = stats.norm(loc=[1], scale=1)
The loc parameter sets the mean of the normal distribution. Here, mean is 0.
Fix the error in the code to plot the probability density function (PDF) of the distribution.
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-3, 3, 100) plt.plot(x, dist.[1](x)) plt.show()
cdf which is cumulative distribution functionpmf which is for discrete distributionsrvs which generates random samplesThe pdf method returns the probability density function values for the given points.
Fill both blanks to create a histogram of 1000 random samples from the distribution and plot the PDF on top.
samples = dist.[1](1000) plt.hist(samples, bins=30, density=[2], alpha=0.6, color='g')
pdf instead of rvs for samplesrvs generates random samples. Setting density=True normalizes the histogram to show probabilities.
Fill both blanks to plot the PDF curve over the histogram of samples.
x = np.linspace(-4, 4, 200) plt.plot(x, dist.[1](x), color='red', label='PDF') plt.hist(samples, bins=30, density=[2], alpha=0.5) plt.legend() plt.show()
cdf instead of pdf for curvepdf for the plotUse pdf to get the curve values. Histogram density must be True to align with PDF.