0
0
SciPydata~20 mins

SciPy with Matplotlib for visualization - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SciPy Visualization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a Gaussian distribution plot code
What will be the output of this code snippet that plots a Gaussian distribution using SciPy and Matplotlib?
SciPy
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

x = np.linspace(-3, 3, 100)
y = norm.pdf(x, 0, 1)
plt.plot(x, y)
plt.title('Gaussian Distribution')
plt.xlabel('x')
plt.ylabel('Probability Density')
plt.show()
AA bar chart with bars increasing from left to right
BA horizontal line at y=1 across the x-axis range
CA line plot showing a bell-shaped curve centered at 0
DA scatter plot with random points scattered around zero
Attempts:
2 left
💡 Hint
Think about what the probability density function of a normal distribution looks like.
data_output
intermediate
2:00remaining
Resulting array from SciPy interpolation
Given the following code using SciPy's interp1d, what is the output array printed?
SciPy
import numpy as np
from scipy.interpolate import interp1d

x = np.array([0, 1, 2, 3])
y = np.array([0, 1, 4, 9])
f = interp1d(x, y)
print(f([1.5, 2.5]))
A[2.5 6.5]
B[1.5 2.5]
C[3.0 7.0]
D[1.0 4.0]
Attempts:
2 left
💡 Hint
Interp1d does linear interpolation between points.
visualization
advanced
2:30remaining
Identify the plot type from SciPy clustering output
This code performs hierarchical clustering and plots a dendrogram. What does the plot visually represent?
SciPy
import numpy as np
from scipy.cluster.hierarchy import dendrogram, linkage
import matplotlib.pyplot as plt

np.random.seed(0)
data = np.random.rand(5, 2)
linked = linkage(data, 'single')
dendrogram(linked, labels=['A', 'B', 'C', 'D', 'E'])
plt.title('Hierarchical Clustering Dendrogram')
plt.show()
AA heatmap of pairwise distances
BA scatter plot of the original data points
CA bar chart showing cluster sizes
DA tree diagram showing how data points cluster step-by-step
Attempts:
2 left
💡 Hint
Dendrograms show hierarchical relationships between clusters.
🔧 Debug
advanced
2:00remaining
Identify the error in SciPy curve fitting code
What error will this code raise when run?
SciPy
import numpy as np
from scipy.optimize import curve_fit

def model(x, a, b):
    return a * x + b

xdata = np.array([1, 2, 3, 4])
ydata = np.array([2, 4, 6, 8])

params, covariance = curve_fit(model, xdata, ydata, p0=[1])
ANo error, code runs successfully
BValueError: p0 must be of length 2 for two parameters
CRuntimeWarning: overflow encountered in multiply
DTypeError: model() missing 1 required positional argument
Attempts:
2 left
💡 Hint
Check the initial guess p0 length matches the number of parameters in the model.
🚀 Application
expert
3:00remaining
Choosing the correct SciPy function for statistical test visualization
You want to visualize the distribution of two independent samples and test if they come from the same distribution using SciPy and Matplotlib. Which approach below correctly combines the test and visualization?
AUse scipy.stats.ks_2samp to test, then plot both samples' histograms with plt.hist
BUse scipy.stats.ttest_ind to test, then plot a scatter plot of the samples
CUse scipy.stats.chisquare to test, then plot a line plot of sample means
DUse scipy.stats.pearsonr to test, then plot a bar chart of correlation coefficients
Attempts:
2 left
💡 Hint
The Kolmogorov-Smirnov test compares distributions; histograms show distributions visually.