๐ Phase 2: Mathematics for Data Science
๐ Topic 7: Descriptive Statistics โ Range, Percentiles, Quartiles, IQR & Five-Number Summary
Welcome back! ๐
In the previous lesson you covered Probability Distributions.
Now weโre moving to Descriptive Statistics โ how we summarize data without predicting the population.
Today weโll cover: Range, Percentiles, Quartiles, IQR, Five-number summary, Outlier detection
These are core for EDA.
๐น 1. What is Descriptive Statistics?
Summarizes key characteristics of a dataset.
Example: Salaries: 30000, 35000, 40000, 45000, 50000
Instead of checking each value, use: Min, Max, Mean, Median, Quartiles, Percentiles, Std Dev
๐น 2. Range
Formula:
Range = Maximum โ Minimum
Example: 10, 20, 30, 40, 50 โ Range = 50 โ 10 = 40
Note: Very sensitive to outliers. 50 โ 500 makes range jump to 490.
๐น 3. Percentiles โญ
Value below which X% of observations fall.
50th Percentile = Median
25th Percentile = 25% at or below
90th Percentile = 90% at or below
๐น 4. Real-World Example
90th percentile score โ 90% marks. It means you did better than โผ90% of people.
๐น 5. Quartiles
Divide data into 4 equal parts:
Q1 = 25th percentile
Q2 = 50th percentile = Median
Q3 = 75th percentile
๐น 6. Visualizing Quartiles
0% ---- Q1 ---- Q2 ---- Q3 ---- 100%
25% 50% 75%
๐น 7. Interquartile Range (IQR) โญ
Formula: IQR = Q3 โ Q1
Example: Q1=20, Q3=60 โ IQR = 40. Middle 50% spans 40 units.
๐น 8. Why IQR Matters
Less affected by outliers than Range.
Data: 10,20,30,40,50,1000 โ Range=990 but IQR ignores the 1000.
๐น 9. Detecting Outliers Using IQR โญ
Lower Bound = Q1 โ 1.5 ร IQR
Upper Bound = Q3 + 1.5 ร IQR
Values outside = potential outliers
๐น 10. Outlier Example
Q1=20, Q3=60 โ IQR=40
Lower = 20-60 = -40
Upper = 60+60 = 120
So < -40 or > 120 are outliers
๐น 11. Five-Number Summary โญ
1. Minimum 2. Q1 3. Median 4. Q3 5. Maximum
Ex: 10, 20, 30, 40, 50
๐น 12. Box Plot
Visualizes the 5-number summary.
Box = Q1 to Q3. Line inside = Median. Whiskers = range without outliers.
๐น 13. Python Example
import numpy as np
data = [10, 20, 30, 40, 50, 60, 70]
q1 = np.percentile(data, 25)
median = np.percentile(data, 50)
q3 = np.percentile(data, 75)
iqr = q3 - q1
print("Q1:", q1, "Median:", median, "Q3:", q3, "IQR:", iqr)
๐น 14. Descriptive Statistics in Pandas
import pandas as pd
df = pd.DataFrame({"Salary": [30000, 35000, 40000, 45000, 50000]})
print(df["Salary"].describe())
describe() gives Count, Mean, Std, Min, 25%, 50%, 75%, Max
๐น 15. Real-World Example
Transactions: Q1=โน500, Median=โน1000, Q3=โน2000 โ IQR=โน1500
Use IQR to flag fraud, bulk orders, errors, or VIP customers. Investigate before deleting.
๐น 16. Range vs IQR
Range: Easy but outlier-sensitive
IQR: Middle 50% only, robust to outliers
๐น 17. Percentile vs Percentage
Percentage = out of 100.
Ex: 80% marks
Percentile = relative position.
Ex: 90th percentile
๐น 18. Common Mistakes
โ 90th percentile = 90% score
โ Deleting all outliers blindly
โ Thinking IQR covers all data
๐ฏ Practice Questions
1. Range of 10, 20, 30, 40, 50 = ?
2. Median = which percentile?
3. Q1=25, Q3=75 โ IQR = ?
4. Upper outlier boundary formula?
5. 5 components of five-number summary?
๐ฏ Key Takeaways
โ Range = Max - Min
โ Q1=25th, Q2=50th=Median, Q3=75th
โ IQR = Q3 - Q1
โ 5-number summary = Min, Q1, Median, Q3, Max
โ Percentile โ Percentage
๐ Double Tap โค๏ธ For More