Challenge - 5 Problems
SciPy Visualization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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()
Attempts:
2 left
💡 Hint
Think about what the probability density function of a normal distribution looks like.
✗ Incorrect
The code uses norm.pdf to compute the probability density function of a normal distribution centered at 0 with standard deviation 1. Plotting this produces a bell-shaped curve.
❓ data_output
intermediate2: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]))
Attempts:
2 left
💡 Hint
Interp1d does linear interpolation between points.
✗ Incorrect
At 1.5, linear interpolation between y=1 at x=1 and y=4 at x=2 gives 2.5. At 2.5, between y=4 at x=2 and y=9 at x=3 gives 6.5.
❓ visualization
advanced2: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()
Attempts:
2 left
💡 Hint
Dendrograms show hierarchical relationships between clusters.
✗ Incorrect
The dendrogram visually shows the order and distance at which data points are merged into clusters.
🔧 Debug
advanced2: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])
Attempts:
2 left
💡 Hint
Check the initial guess p0 length matches the number of parameters in the model.
✗ Incorrect
The model function has two parameters (a, b), but p0 is given as a list with one element. curve_fit expects p0 length to match parameter count.
🚀 Application
expert3: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?
Attempts:
2 left
💡 Hint
The Kolmogorov-Smirnov test compares distributions; histograms show distributions visually.
✗ Incorrect
ks_2samp tests if two samples come from the same distribution. Plotting histograms helps visualize their distribution shapes.