Descriptive Statistics
โ1. Variable
- A variable is a piece of information that can have different values. In simple words:
A variable is something we can measure, record, or observe.
If we collect data about customers, each customer may have different values for:
age,gender,income,expenditure,city,number_of_ordersEach of these is called a variable. - Variables are mainly divided into two types: - Numerical Variables - Categorical Variables
1.1 ๐ฆ What is a Variable?
1.2 ๐ข Types of Variables

Numerical Variables
| Type | Description | Example |
|---|---|---|
| Continuous ๐ | Measurable Value with decimal | Height, Weight, Temperature |
| Discrete ๐ข | Countable Values. | Total Books, Number of Cars, Order Count |
Type of Numerical Variables
Categorical Variables
| Type | Description | Example |
|---|---|---|
| Nominal ๐ท๏ธ | Categories with no specific order. | Colors, Gender, Blood Group |
| Ordinal ๐ถ | Categories with a specific order. | Education Level, Rating |
Type of Categorical Variables
2. Population vs Sample
- A population is the entire group we want to study. Examples: - All students in a school - All customers of a company - All people living in a city - All products sold by a shop
- A sample is a smaller group selected from the population. We study the sample to understand the larger population. If a city has 1 million people, it may be difficult to ask everyone about their income. So, we may randomly select 1,000 people and study them. Here: Population = 1 million people Sample = 1,000 selected people
- We use samples because studying the entire population can be: - Too expensive ๐ฐ - Too time-consuming โฐ - Difficult to manage ๐ - Sometimes impossible ๐ต So, we study a smaller group and use it to make conclusions about the larger group.
- A sample should fairly represent the population. This means the sample should be similar to the population. If we want to know the opinion of all students in a school, we should not ask only Grade 10 students. We should include students from different grades. ๐ Simple idea: A good sample gives a fair picture of the whole population.
2.1 ๐ What is Population?
2.2 ๐ฅ What is Sample?
2.3 ๐ค Why Do We Use Samples?
2.4 ๐ฏ Representative Sample

- Sampling bias happens when the sample does not properly represent the population. If we ask only cricket fans about their favorite sport, most may say cricket. But that does not mean everyone likes cricket the most.
2.5 โ ๏ธ Sampling Bias
3. Statistics
- Statistics is the science of: โ Collecting data โ Organizing data โ Analyzing data โ Understanding data โ Presenting data clearly In simple words: Statistics helps us make sense of data.
- There are two main types of statistics: - Descriptive Statistics - Inferential Statistics
3.1 ๐ What is Statistics?
3.2 ๐ Types of Statistics
Types of Statistics
| Type | Description | Example |
|---|---|---|
| Descriptive Statistics ๐ | Summarizes and describes existing data. | Mean, Median, Mode, Standard Deviation |
| Inferential Statistics ๐ฎ | Uses sample data to make conclusion about a larger group | Hypothesis testing, Confidence intervals, Regression analysis |
Types and Examples of Statistics
4. Central Tendency
- Central tendency tells us the center or typical value of data. It helps answer: What value represents this data best? The three most common measures are: - Mean - Median - Mode
- Mean is the arithmetic average of numbers.
Formula:
Mean = Sum of all values / Number of valuesFor data:[2, 1, 2, 5, 100],mean = (2 + 1 + 2 + 5 + 100) / 5mean = 110 / 5mean = 22So, the mean is22. โ ๏ธ Mean can be affected by very large or very small values called outliers. ๐ In this example, 100 makes the mean much larger than most values. - Median is the middle value after sorting the data.
Steps:
- 1. Sort the data
- 2. Find the middle value
Example:
Original data:
[2, 1, 2, 5, 100]Sorted data:[1, 2, 2, 5, 100]Middle value:2So, the median is2. โ Median is useful when data has outliers. ๐ Here, median 2 represents the data better than mean 22.
4.1 ๐ฏ What is Central Tendency?
4.2 โ Mean
4.3 ๐ Median

- Mode is the value that appears most often.
Example:
For data:
[2, 1, 2, 5, 100]The value 2 appears two times. So, the mode is2. Mode can be used for both: - Numerical data (like test scores) - Categorical data (like favorite colors)data = ["Red", "Blue", "Red", "Green", "Red"]Mode isRedbecause it appears most often.
4.4 ๐ Mode
4.5 ๐ง When to Use Mean, Median, and Mode
| Measure | Best Used When |
|---|---|
| Mean โ | Data is numerical and has no extreme outliers. |
| Median ๐ | Data has outliers or is unevenly spread. |
| Mode ๐ | Data is categorical or you want most common value. |
When to use Mean, Median, and Mode
5. Percentiles and Quartiles
- Percentiles and quartiles tell us the position of a value compared to the rest of the data. They help answer: Is this value high, low, or average compared to others?
- Suppose a student scores
60 / 100. Is this good or bad? We cannot say clearly unless we know how other students scored. - If most students scored below 60, then 60 is good. โ - If most students scored above 60, then 60 may not be good. โ ๏ธ So, position matters. - Percentiles divide data into 100 equal parts. The p-th percentile means:
p% of the data is below that value.If a student is in the 90th percentile, it means: The student scored better than 90% of the students. - Quartiles divide data into 4 equal parts. There are three main quartiles: Q1, Q1 and Q3.
5.1 What are Percentiles and Quartiles?
5.2 ๐ Simple Example
5.3 ๐ Percentiles
5.4 ๐งฑ Quartiles
Quartiles Table
| Quartile | Position | Meaning |
|---|---|---|
| Q1 (1st Quartile) | 25th Percentile | 25% of the data is below this value. |
| Q2 (2nd Quartile) | 50th Percentile | Median |
| Q3 (3rd Quartile) | 75th Percentile | 75% of the data is below this value. |
Understanding Quartiles

- IQR shows the spread of the middle 50% of the data.
Formula:
IQR = Q3 - Q1IQR is useful because it is not strongly affected by outliers. Detecting Outliers Using IQR Values are often considered outliers if they are:Below Q1 - 1.5 ร IQR(lower limit) orAbove Q3 + 1.5 ร IQR(upper limit) ๐ Simple idea: IQR helps us find values that are unusually small or unusually large.
Interquartile Range: IQR
6. Dispersion
- Dispersion tells us how spread out the data is. It helps answer: Are the values close together or far apart?
Example:
Dataset A:
[38, 40, 42]Dataset B:[5, 20, 95]Both datasets have mean 40. But Dataset B is much more spread out. That spread is called dispersion. - The common measures are: - Range - Variance - Standard Deviation
- Range is the difference between the maximum and minimum value.
Formula:
Range = Max - MinExample: For data:[2, 1, 2, 5, 100]Range:100 - 1 = 99So, the range is99. ๐ Simple idea: Range gives a quick idea of spread, but it is highly affected by outliers. - Variance tells us how far values are from the mean.
Simple meaning:
- High variance โ Values are spread far from the mean
- Low variance โ Values are close to the mean
Formula:
Variance = ฮฃ(Xi - Xฬ)ยฒ / N
6.1 ๐ What is Dispersion?
6.2 Common Measures of Dispersion
6.3 ๐ Range
6.4 ๐ Variance

- Standard deviation is the square root of variance.
Formula:
Standard Deviation = โVarianceStandard deviation is easier to understand than variance because it is in the same unit as the original data. ๐ Simple idea: Standard deviation tells us how much values usually differ from the average.
6.5 ๐ Standard Deviation
7. Example: Dispersion Calculation
- For data points
[5, 20, 95]: Mean:(5 + 20 + 95) / 3 = 120 / 3 = 40Minimum:5Maximum:95Range:95 - 5 = 90
7.1 Given Data
7.2 Variance and Standard Deviation Calculation
| Value (X) | Difference from Mean (X - Xฬ) | Squared Difference (X - Xฬ)ยฒ |
|---|---|---|
| 5 | 5 - 40 = -35 | (-35)ยฒ = 1225 |
| 20 | 20 - 40 = -20 | (-20)ยฒ = 400 |
| 95 | 95 - 40 = 55 | (55)ยฒ = 3025 |
| Variance | (1225 + 400 + 3025) / 3 = 1550 | |
| Standard Deviation | sqrt(1550) = 39.37 |
Example showing calculation of Variance and Standard Deviation
8. Covariance and Correlation
- In Data Science, we often want to know how two variables are related. Examples: - Does more study time lead to higher marks? - Does more advertising increase sales? - Does temperature affect ice cream sales? - Does income affect spending? To study relationships, we use: Covariance and Correlation
- Covariance tells us whether two variables move together.
Formula:
Cov(X, Y) = ฮฃ((Xi - Xฬ)(Yi - ศฒ)) / N
8.1 ๐ Why Do We Study Relationships Between Variables?
8.2 ๐ Covariance
Covariance Types
| Type | Description | Example |
|---|---|---|
| Positive ๐ | Both variables increase or decrease together. | More study time, Higher marks |
| Negative ๐ | One variable increases while the other decreases. | More Travel, Less Saving |
| Zero โ | No clear relationship between the two variables. | Shoe Size and Exam Marks |
- While covariance gave idea of direction but there is no strength indication. Correlation tells us both:
โ
Direction of relationship
โ
Strength of relationship
Correlation always lies between
-1and+1. Formula:Correlation = Cov(X, Y) / (Std(X) ร Std(Y))
8.3 ๐ Correlation
Interpretation of Correlation Values
| Correlation | Meaning |
|---|---|
| +1 | Perfect Positive Correlation: Both variables increase together. |
| -1 | Perfect Negative Correlation: One variable increases while the other decreases. |
| 0 | No or Very Weak Correlation: No clear relationship between the two variables. |
| 0.5 | Moderate Positive Correlation: As one variable increases, the other tends to increase moderately. |
Interpretation of Correlation Values

9. Example: Covariance and Correlation Calculation
X = [5, 20, 95]Y = [10, 30, 50]Mean of X:Xฬ = (5 + 20 + 95) / 3 = 40Mean of Y:ศฒ = (10 + 30 + 50) / 3 = 30
9.1 Given Data
9.2 Calculation table of Covariance and Correlation
| X | X - Xฬ | (X - Xฬ)ยฒ | Y | Y - ศฒ | (Y - ศฒ)ยฒ | (X - Xฬ) * (Y - ศฒ) |
|---|---|---|---|---|---|---|
| 5 | 5 - 40 = -35 | (-35)ยฒ = 1225 | 10 | 10 - 30 = -20 | 400 | (-35) * (-20) = 700 |
| 20 | 20 - 40 = -20 | (-20)ยฒ = 400 | 30 | 30 - 30 = 0 | 0 | (-20) * (0) = 0 |
| 95 | 95 - 40 = 55 | 55ยฒ = 3025 | 50 | 50 - 30 = 20 | 400 | 55 * 20 = 1100 |
Example showing calculation of Covariance and Correlation
Var(X) = (1225 + 400 + 3025) / 3 = 4650 / 3 = 1550Var(Y) = (400 + 0 + 400) / 3 = 800 / 3 = 266.67Cov(X, Y) = (700 + 0 + 1100) / 3 = 1800 / 3 = 600Std(X) = โ1550 = 39.37Std(Y) = โ266.67 = 16.33Correlation = 600 / (39.37 ร 16.33) = 600 / 642.86 = 0.93๐ Interpretation: Correlation is 0.93, which means X and Y have a strong positive relationship.
Calculations
10. Spearman Rank Correlation
- Spearman Rank Correlation is used when data has rank or order. It is useful for ordinal data.
Examples of ordinal data:
- T-shirt size: S, M, L, XL
- Rating: Poor, Average, Good, Excellent
- Rank in class: 1st, 2nd, 3rd
- Satisfaction level: Low, Medium, High
T-shirt sizes have order:
S < M < L < XL. So, we can rank as:S = 1, M = 2, L = 3, XL = 4Formula:ฯ = 1 - (6 ร ฮฃdยฒ) / (n ร (nยฒ - 1)) T-shirt Size = ['M', 'S', 'L', 'XL']Customer Satisfaction = [3, 4, 2, 5]
10.1 ๐ What is Spearman Rank Correlation?
10.4 Calculation Example
Spearman Rank Correlation for T-shirt Size and Satisfaction
| T-shirt Size | Rank T-shirt (R1) | Satisfaction | Rank Satisfaction (R2) | d = R1 - R2 | dยฒ |
|---|---|---|---|---|---|
| M | 2 | 3 | 2 | 2 - 2 = 0 | 0ยฒ = 0 |
| S | 1 | 4 | 3 | 1 - 3 = -2 | (-2)ยฒ = 4 |
| L | 3 | 2 | 1 | 3 - 1 = 2 | 2ยฒ = 4 |
| XL | 4 | 5 | 4 | 4 - 4 = 0 | 0ยฒ = 0 |
Ranking and calculation of Spearman correlation
- The table above shows each T-shirt size and satisfaction score converted into ranks, along with the rank difference (d) and squared difference (dยฒ) needed for the formula.
Calculation
n = 4ฮฃdยฒ = 0 + 4 + 4 + 0 = 8n(nยฒ - 1) = 4(4ยฒ - 1) = 4(16 - 1) = 60ฯ = 1 - (6 x 8) / 60 = 1 - 48/60 = 1 - 0.8 = 0.2๐ Interpretation: Spearman correlation is 0.2, which shows a weak positive relationship between T-shirt size and customer satisfaction.
Ranking Table
11. Probability
- Probability tells us how likely something is to happen. It is a number between
0and1. Interpretation: 0 โ Impossible 1 โ Certain 0.5 โ 50% chance โ Simple Example If a weather app says:Probability of rain = 0.8It means: There is an 80% chance of rain. So, you may decide to carry an umbrella. P(A) = Number of favorable outcomes / Total number of outcomesExample: If a coin is flipped, possible outcomes are:Head, TailProbability of getting Head:P(Head) = 1 / 2 = 0.5So, there is a 50% chance of getting Head.- Rule 1: Event and Not Event
P(A) + P(not A) = 1Example: If probability of rain is 0.8:P(no rain) = 1 - 0.8 = 0.2Rule 2: A or BP(A or B) = P(A) + P(B) - P(A and B)This is used when we want either event A or event B to happen.
11.1 ๐ฒ What is Probability?
11.2 Probability Formula
11.3 Basic Probability Rules
Practice QuestionsNot started
Central Tendency
Question 1 of 2
- Write a function
calc_meanthat takes a list of numbers and returns mean. - Write a function
calc_medianthat takes a list of numbers and returns median. - Write a function
calc_modethat takes a list of numbers and returns mode. - Test functions with the dataset
[2, 1, 2, 5, 100]. Verify mean =22, median =2, mode =2. - Write a function
calc_percentilethat takes a list of numbers and a percentile value (0-100). Returns the corresponding pth percentile value i.e.[p * (n+1) / 100]th itemin sorted data. - Write a function
calc_quartilesthat takes a list of numbers and returnsQ1,Q2,Q3. Reuse above function for this.
- Write a function
Dispersion
Question 2 of 2
- Write a function
calc_rangethat takes a list of numbers and returns range (L -S). - Write a function
calc_covariancethat takes two lists of numbers and returns covariance. - Write a function
calc_variancethat takes a list of numbers and returns variance. - Write a function
calc_correlationthat takes two lists of numbers and return correlation. - Test functions with the datasets X =
[5, 20, 95]and Y =[10, 30, 50]. Verify range(X) =90, covariance =600, variance(X) =4650, correlation =0.54. - Write a function
calc_bmithat takes height (in meters) and weight (in kg) and returns BMI.bmi = weight / (height * height).
- Write a function
