0
0
SciPydata~10 mins

SciPy with Matplotlib for visualization - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the SciPy stats module.

SciPy
from scipy import [1]
Drag options to blanks, or click blank then click option'
Asignal
Boptimize
Cintegrate
Dstats
Attempts:
3 left
💡 Hint
Common Mistakes
Importing optimize instead of stats
Using integrate which is for integration
Using signal which is for signal processing
2fill in blank
medium

Complete the code to create a normal distribution object with mean 0 and standard deviation 1.

SciPy
dist = stats.norm(loc=[1], scale=1)
Drag options to blanks, or click blank then click option'
A0
B2
C-1
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting mean to 1 instead of 0
Using negative mean without reason
Confusing scale with mean
3fill in blank
hard

Fix the error in the code to plot the probability density function (PDF) of the distribution.

SciPy
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-3, 3, 100)
plt.plot(x, dist.[1](x))
plt.show()
Drag options to blanks, or click blank then click option'
Acdf
Bpmf
Cpdf
Drvs
Attempts:
3 left
💡 Hint
Common Mistakes
Using cdf which is cumulative distribution function
Using pmf which is for discrete distributions
Using rvs which generates random samples
4fill in blank
hard

Fill both blanks to create a histogram of 1000 random samples from the distribution and plot the PDF on top.

SciPy
samples = dist.[1](1000)
plt.hist(samples, bins=30, density=[2], alpha=0.6, color='g')
Drag options to blanks, or click blank then click option'
Arvs
BTrue
CFalse
Dpdf
Attempts:
3 left
💡 Hint
Common Mistakes
Using pdf instead of rvs for samples
Setting density to False causing mismatch with PDF
Not setting density parameter at all
5fill in blank
hard

Fill both blanks to plot the PDF curve over the histogram of samples.

SciPy
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()
Drag options to blanks, or click blank then click option'
Acdf
BTrue
Cpdf
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using cdf instead of pdf for curve
Setting histogram density to False
Not calling pdf for the plot