Bird
Raised Fist0
SciPydata~20 mins

Probability density and cumulative functions in SciPy - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Probability Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of PDF calculation for normal distribution
What is the output of this code snippet that calculates the probability density function (PDF) of a normal distribution at x=0?
SciPy
from scipy.stats import norm
result = norm.pdf(0, loc=0, scale=1)
print(round(result, 4))
A0.3989
B0.5000
C1.0000
D0.0000
Attempts:
2 left
💡 Hint
Recall the formula for the PDF of a standard normal distribution at zero.
❓ data_output
intermediate
2:00remaining
Cumulative distribution function values for uniform distribution
What is the output array of cumulative distribution function (CDF) values for a uniform distribution between 0 and 10 at points [0, 5, 10, 15]?
SciPy
from scipy.stats import uniform
import numpy as np
points = np.array([0, 5, 10, 15])
cdf_values = uniform.cdf(points, loc=0, scale=10)
print(np.round(cdf_values, 2))
A[0.00 0.25 0.50 0.75]
B[0.00 0.40 0.80 1.00]
C[0.00 0.50 1.00 1.00]
D[0.10 0.50 0.90 1.00]
Attempts:
2 left
💡 Hint
CDF of uniform distribution increases linearly from 0 to 1 over the scale.
❓ visualization
advanced
3:00remaining
Plot PDF and CDF of exponential distribution
Which option produces the correct plot showing both the PDF and CDF of an exponential distribution with rate 1 over the range 0 to 5?
SciPy
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import expon
x = np.linspace(0, 5, 100)
plt.plot(x, expon.pdf(x), label='PDF')
plt.plot(x, expon.cdf(x), label='CDF')
plt.legend()
plt.show()
APlot with PDF and CDF both starting at 0 and increasing to 1
BPlot with PDF curve starting at 1 and decreasing, CDF curve starting at 0 and increasing to 1
CPlot with PDF curve increasing, CDF curve decreasing
DPlot with flat PDF and CDF curves
Attempts:
2 left
💡 Hint
Remember the shape of exponential PDF and CDF functions.
🧠 Conceptual
advanced
2:00remaining
Understanding the relationship between PDF and CDF
Which statement correctly describes the relationship between the probability density function (PDF) and the cumulative distribution function (CDF) of a continuous random variable?
AThe PDF is the square of the CDF.
BThe PDF is the integral of the CDF from negative infinity to x.
CThe PDF and CDF are always equal for all x.
DThe CDF is the integral of the PDF from negative infinity to x.
Attempts:
2 left
💡 Hint
Think about how cumulative probability accumulates from the density.
🔧 Debug
expert
2:00remaining
Identify the error in this code calculating normal distribution CDF
What error does this code produce when trying to calculate the CDF of a normal distribution at x=1?
SciPy
from scipy.stats import norm
result = norm.cdf(1, mean=0, std=1)
print(result)
ATypeError: cdf() got an unexpected keyword argument 'mean'
BValueError: scale must be positive
CSyntaxError: invalid syntax
DOutput: 0.8413
Attempts:
2 left
💡 Hint
Check the parameter names for scipy.stats.norm.cdf.

Practice

(1/5)
1. What does the Probability Density Function (PDF) represent in a data distribution?
easy
A. The average value of the data
B. The likelihood of a value occurring at a specific point
C. The total probability up to a certain value
D. The maximum value in the data

Solution

  1. Step 1: Understand PDF meaning

    The PDF shows how dense or likely values are at specific points in a distribution.
  2. Step 2: Differentiate from CDF

    The CDF shows total probability up to a point, not the likelihood at a point.
  3. Final Answer:

    The likelihood of a value occurring at a specific point -> Option B
  4. Quick Check:

    PDF = Likelihood at point [OK]
Hint: PDF shows likelihood at exact points, not cumulative [OK]
Common Mistakes:
  • Confusing PDF with CDF
  • Thinking PDF gives total probability
  • Assuming PDF gives average or max value
2. Which of the following is the correct way to import the cumulative distribution function (CDF) for a normal distribution from scipy.stats?
easy
A. import norm from scipy.stats; norm.cdf(x)
B. import scipy.stats.norm as norm; norm.cdf(x)
C. from scipy import norm; norm.cdf(x)
D. from scipy.stats import norm; norm.cdf(x)

Solution

  1. Step 1: Recall scipy.stats import syntax

    The correct import for normal distribution functions is from scipy.stats import norm.
  2. Step 2: Use norm.cdf(x) to get CDF

    After import, norm.cdf(x) computes the cumulative distribution function at x.
  3. Final Answer:

    from scipy.stats import norm; norm.cdf(x) -> Option D
  4. Quick Check:

    Correct import and usage = from scipy.stats import norm; norm.cdf(x) [OK]
Hint: Use 'from scipy.stats import norm' for normal distribution functions [OK]
Common Mistakes:
  • Wrong import syntax causing errors
  • Using 'import scipy.stats.norm as norm' which is invalid
  • Trying to import norm directly from scipy
3. What is the output of the following code snippet?
from scipy.stats import norm
result = norm.pdf(0, loc=0, scale=1)
print(round(result, 3))
medium
A. 0.399
B. 0.500
C. 1.000
D. 0.000

Solution

  1. Step 1: Understand norm.pdf at mean

    For a normal distribution with mean 0 and std 1, PDF at 0 is 1/sqrt(2*pi) ≈ 0.3989.
  2. Step 2: Round the result

    Rounding 0.3989 to 3 decimals gives 0.399.
  3. Final Answer:

    0.399 -> Option A
  4. Quick Check:

    PDF at mean = 0.399 [OK]
Hint: PDF at mean of standard normal ≈ 0.399 [OK]
Common Mistakes:
  • Confusing PDF with CDF value
  • Rounding incorrectly
  • Assuming PDF at mean is 0.5
4. Identify the error in this code that tries to calculate the CDF of a normal distribution at x=1:
import scipy.stats as stats
cdf_value = stats.norm.pdf(1, loc=0, scale=1)
print(cdf_value)
medium
A. Using pdf() instead of cdf() to get cumulative probability
B. Missing import statement for norm
C. Incorrect parameters for norm.pdf
D. Syntax error in print statement

Solution

  1. Step 1: Check function used for CDF calculation

    The code uses norm.pdf which gives probability density, not cumulative probability.
  2. Step 2: Correct function for cumulative probability

    To get cumulative probability, norm.cdf should be used instead of norm.pdf.
  3. Final Answer:

    Using pdf() instead of cdf() to get cumulative probability -> Option A
  4. Quick Check:

    Use cdf() for cumulative probability [OK]
Hint: Use cdf() for cumulative, pdf() for density [OK]
Common Mistakes:
  • Mixing pdf and cdf functions
  • Assuming pdf returns cumulative values
  • Ignoring function purpose
5. You have a dataset of exam scores that roughly follow a normal distribution with mean 70 and standard deviation 10. Using scipy, how would you find the probability that a student scored less than 85?
hard
A. Use norm.cdf(70, loc=85, scale=10) to get cumulative probability
B. Use norm.pdf(85, loc=70, scale=10) to get cumulative probability
C. Use norm.cdf(85, loc=70, scale=10) to get cumulative probability
D. Use norm.pdf(70, loc=85, scale=10) to get cumulative probability

Solution

  1. Step 1: Identify correct function for cumulative probability

    To find probability of scoring less than 85, use the cumulative distribution function norm.cdf.
  2. Step 2: Use correct parameters for mean and std

    Set loc=70 (mean) and scale=10 (std deviation), and evaluate at 85.
  3. Final Answer:

    Use norm.cdf(85, loc=70, scale=10) to get cumulative probability -> Option C
  4. Quick Check:

    norm.cdf(value, loc=mean, scale=std) = cumulative probability [OK]
Hint: CDF with loc=mean, scale=std, value=threshold [OK]
Common Mistakes:
  • Using pdf instead of cdf for cumulative probability
  • Swapping mean and value parameters
  • Confusing scale with loc
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard