Descriptive Statistics (mean, median, variance)
Central tendency
Section titled “Central tendency”- Sensitive to outliers
- Good for symmetric distributions
import numpy as np
x = np.array([10, 12, 12, 13, 12, 11, 100])
print(np.mean(x))Median
Section titled “Median”- Robust to outliers
import numpy as np
x = np.array([10, 12, 12, 13, 12, 11, 100])
print(np.median(x))Useful for categorical data.
import numpy as np
from scipy import stats
x = np.array([1, 1, 2, 2, 2, 3])
print(stats.mode(x, keepdims=True))Spread (variability)
Section titled “Spread (variability)”- Range: max - min (very sensitive)
- Variance: average squared distance from mean
- Standard deviation (std): sqrt(variance)
import numpy as np
x = np.array([10, 12, 12, 13, 12, 11, 100])
print("var:", np.var(x, ddof=1))
print("std:", np.std(x, ddof=1))IQR (interquartile range)
Section titled “IQR (interquartile range)”Robust measure of spread.
import numpy as np
x = np.array([10, 12, 12, 13, 12, 11, 100])
q1 = np.percentile(x, 25)
q3 = np.percentile(x, 75)
print("IQR:", q3 - q1)Quick checklist
Section titled “Quick checklist”- Use median/IQR when outliers exist
- Use mean/std when distribution is roughly symmetric
- Always visualize (histogram/boxplot) before trusting summary stats
How mean and median relate
Section titled “How mean and median relate”flowchart TD A["Do you have outliers
or a skewed shape?"] -->|"Yes"| B["Use median
(robust)"] A -->|"No"| C["Use mean
(uses every value)"] D["Is the data categorical?"] --> E["Use mode"]
Visualize it
Section titled “Visualize it”The mean is pulled toward extreme values because it uses every number in the calculation. The median only cares about the middle position, so it barely moves when one point is far away. Watch the outlier drag the mean marker to the right while the median stays put:
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Mean vs. median with an outlier
Section titled “Exercise 1 – Mean vs. median with an outlier”Exercise 2 – Variance and standard deviation
Section titled “Exercise 2 – Variance and standard deviation”Exercise 3 – IQR to spot spread
Section titled “Exercise 3 – IQR to spot spread”Continue to Probability Basics to build the foundation for confidence intervals and hypothesis tests.
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading