📖 Scenario: Imagine you work in a bakery that wants to understand the daily weight of its bread loaves. The weights follow a pattern called the normal distribution, which looks like a bell curve. You will use Python and SciPy to explore this pattern.
🎯 Goal: You will create data representing bread weights, set parameters for the normal distribution, calculate probabilities for certain weights, and finally display the results.
📋 What You'll Learn
Create a list of bread weights in grams
Set the mean and standard deviation for the normal distribution
Use SciPy to calculate the probability density function (PDF) for each weight
Print the list of weights and their corresponding PDF values
💡 Why This Matters
🌍 Real World
Normal distributions are common in quality control, like checking if bread weights stay consistent in a bakery.
💼 Career
Understanding and using normal distributions is important for data analysts and scientists to model real-world data and make decisions.
Progress0 / 4 steps
1
Create a list of bread weights
Create a list called bread_weights with these exact values: 250, 255, 260, 265, 270.
SciPy
Hint
Use square brackets to create a list and separate the numbers with commas.
2
Set mean and standard deviation
Create two variables: mean_weight set to 260 and std_dev set to 7.
SciPy
Hint
Use simple assignment to create these variables.
3
Calculate PDF values using SciPy
Import norm from scipy.stats. Then create a list called pdf_values that contains the PDF values for each weight in bread_weights using norm.pdf(weight, mean_weight, std_dev) inside a list comprehension.
SciPy
Hint
Use a list comprehension to apply norm.pdf to each weight.
4
Print the weights and their PDF values
Use a for loop with variables weight and pdf to iterate over zip(bread_weights, pdf_values). Inside the loop, print the weight and its PDF value formatted as: Weight: {weight}g, PDF: {pdf:.5f}.
SciPy
Hint
Use zip to pair weights and PDF values, then print each pair with formatted strings.
Practice
(1/5)
1. What does the normal distribution model in data science?
easy
A. Data with no variation
B. Data with only positive values
C. Data sorted in ascending order
D. Data spread around an average value
Solution
Step 1: Understand the normal distribution concept
The normal distribution describes how data points are spread around a central average (mean).
Step 2: Identify the correct description
Among the options, only data spread around an average matches the normal distribution's purpose.
Final Answer:
Data spread around an average value -> Option D
Quick Check:
Normal distribution = data around average [OK]
Hint: Normal distribution centers data around mean [OK]
Common Mistakes:
Thinking normal distribution only has positive values
Confusing normal distribution with sorted data
Assuming no variation in normal distribution
2. Which of the following is the correct way to import the normal distribution functions from scipy.stats?
easy
A. import scipy.norm
B. from scipy.stats import norm
C. from scipy import normal
D. import stats.norm
Solution
Step 1: Recall scipy.stats import syntax
The normal distribution functions are in scipy.stats under the name 'norm'.
Step 2: Match correct import statement
Only 'from scipy.stats import norm' correctly imports the normal distribution functions.
Final Answer:
from scipy.stats import norm -> Option B
Quick Check:
Correct import = from scipy.stats import norm [OK]
Hint: Use 'from scipy.stats import norm' to access normal distribution [OK]
Common Mistakes:
Using 'import scipy.norm' which does not exist
Trying 'from scipy import normal' which is incorrect
Importing 'stats.norm' without scipy prefix
3. What is the output of this code?
from scipy.stats import norm
result = norm.cdf(0, loc=0, scale=1)
print(round(result, 2))
medium
A. 1.00
B. 0.00
C. 0.50
D. 0.84
Solution
Step 1: Understand norm.cdf at mean
norm.cdf(x, loc, scale) gives the probability data is less than x. At x=0 with mean=0, scale=1, it is the 50th percentile.
Step 2: Calculate and round the result
The cumulative probability at mean is 0.5, rounding to 2 decimals gives 0.50.
Final Answer:
0.50 -> Option C
Quick Check:
norm.cdf(mean) = 0.5 [OK]
Hint: CDF at mean of normal = 0.5 [OK]
Common Mistakes:
Confusing PDF with CDF values
Expecting 0 or 1 instead of 0.5 at mean
Rounding errors ignoring decimals
4. Find the error in this code snippet:
from scipy.stats import norm
prob = norm.pdf(1, mean=0, scale=1)
print(prob)
medium
A. Parameter 'mean' should be 'loc'
B. Missing import statement
C. norm.pdf does not exist
D. scale must be an integer
Solution
Step 1: Check parameter names for norm.pdf
norm.pdf uses 'loc' for mean, not 'mean'. Using 'mean' causes an error.
Step 2: Identify correct parameter
Replace 'mean=0' with 'loc=0' to fix the code.
Final Answer:
Parameter 'mean' should be 'loc' -> Option A
Quick Check:
Use loc for mean in norm functions [OK]
Hint: Use 'loc' not 'mean' for normal distribution mean [OK]
Common Mistakes:
Using 'mean' instead of 'loc' parameter
Assuming norm.pdf is missing
Thinking scale must be integer
5. You want to find the probability that a value from a normal distribution with mean 10 and standard deviation 2 is less than 13. Which code correctly calculates this using scipy?
hard
A. norm.cdf(13, loc=10, scale=2)
B. norm.pdf(13, loc=10, scale=2)
C. norm.cdf(10, loc=13, scale=2)
D. norm.sf(13, loc=10, scale=2)
Solution
Step 1: Identify the function for cumulative probability
To find probability less than a value, use norm.cdf with the value, mean (loc), and std dev (scale).
Step 2: Match parameters to the problem
Value is 13, mean is 10, std dev is 2, so norm.cdf(13, loc=10, scale=2) is correct.
Final Answer:
norm.cdf(13, loc=10, scale=2) -> Option A
Quick Check:
Use norm.cdf(value, loc=mean, scale=std) [OK]
Hint: Use norm.cdf for probability less than a value [OK]
Common Mistakes:
Using norm.pdf instead of norm.cdf
Swapping loc and value parameters
Using norm.sf which gives probability greater than value
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.