Fixed Top Ad (Local Preview)800x90 โ€ข Slot 6608427872

Descriptive Statistics

โœ•

1. Variable

    1.1 ๐Ÿ“ฆ What is a Variable?
    1. 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_orders Each of these is called a variable.
    1.2 ๐Ÿ”ข Types of Variables
    1. Variables are mainly divided into two types: - Numerical Variables - Categorical Variables
Types of Variables
Types of Variables
Numerical Variables
TypeDescriptionExample
Continuous ๐Ÿ“Measurable value; can include decimalsHeight, Weight, Temperature
Discrete ๐Ÿ”ขCountable values, usually whole numbersTotal Books, Number of Cars, Order Count
Types of Numerical Variables
Categorical Variables
TypeDescriptionExample
Nominal ๐Ÿท๏ธCategories with no meaningful order.Colors, Gender, Blood Group
Ordinal ๐Ÿ“ถCategories with meaningful order.Education Level, Rating
Types of Categorical Variables

2. Population vs Sample

    2.1 ๐ŸŒ What is Population?
    1. 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
    2.2 ๐Ÿ‘ฅ What is Sample?
    1. 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
    2.3 ๐Ÿค” Why Do We Use Samples?
    1. 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.
    2.4 ๐ŸŽฏ Representative Sample
    1. A sample should fairly represent the population, meaning it should give a balanced picture of the whole group. 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. ๐Ÿ“Œ A good sample gives a fair picture of the whole population.
Population vs Sample
Population vs Sample
    2.5 โš ๏ธ Sampling Bias
    1. 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. ๐Ÿ“Œ A biased sample can lead to wrong conclusions.

3. Statistics

    3.1 ๐Ÿ“Š What is Statistics?
    1. 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.
    3.2 ๐Ÿ“‹ Types of Statistics
    1. There are two main types of statistics: - Descriptive Statistics - Inferential Statistics
Types of Statistics
TypeDescriptionExample
Descriptive Statistics ๐Ÿ“‰Summarizes and describes existing data.Mean, Median, Mode, Standard Deviation
Inferential Statistics ๐Ÿ”ฎUses sample data to make conclusions about a larger groupHypothesis testing, Confidence intervals, Prediction from sample data
Types and Examples of Statistics

4. Central Tendency

    4.1 ๐ŸŽฏ What is Central Tendency?
    1. 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
    4.2 โž— Mean
    1. Mean is the arithmetic average of numbers. Formula: Mean = Sum of all values / Number of values For data: [2, 1, 2, 5, 100], mean = (2 + 1 + 2 + 5 + 100) / 5 = 22 โš ๏ธ 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.
    4.3 ๐Ÿ“ Median
    1. 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: 2 So, the median is 2. โœ… Median is useful when data has outliers. ๐Ÿ“Œ Here, median 2 represents the data better than mean 22.
Effect of Outlier on Mean, Median and Mode
Effect of Outlier on Mean, Median and Mode
    4.4 ๐Ÿ” Mode
    1. Mode is the value that appears most often. Example: For data: [2, 1, 2, 5, 100] The value 2 appears most often, so the mode is 2. data = ["Red", "Blue", "Red", "Green", "Red"] Mode is Red because it appears most often. Mode works for both numerical and categorical data.
4.5 ๐Ÿง  When to Use Mean, Median, and Mode
MeasureBest 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

    5.1 ๐Ÿ“ What are Percentiles and Quartiles?
    1. 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?
    5.2 ๐ŸŽ“ Simple Example
    1. 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.
    5.3 ๐Ÿ“Š Percentiles
    1. 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.
    5.4 ๐Ÿงฑ Quartiles
    1. Quartiles divide data into 4 equal parts. The three main quartile values are Q1, Q2, and Q3.
Quartiles Table
QuartilePositionMeaning
Q1 (1st Quartile)25th Percentile25% of the data is below this value.
Q2 (2nd Quartile)50th PercentileMedian
Q3 (3rd Quartile)75th Percentile75% of the data is below this value.
Understanding Quartiles
Box Plot showing Quartiles and Outliers
Box Plot showing Quartiles and Outliers
    Interquartile Range: IQR
    1. IQR shows the spread of the middle 50% of the data. Formula: IQR = Q3 - Q1 IQR 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) or Above Q3 + 1.5 ร— IQR (upper limit) ๐Ÿ“Œ IQR helps us find values that are unusually small or unusually large.

6. Dispersion

    6.1 ๐Ÿ“ What is Dispersion?
    1. 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.
    6.2 Common Measures of Dispersion
    1. The common measures are: - Range - Variance - Standard Deviation
    6.3 ๐Ÿ“ Range
    1. Range is the difference between the maximum and minimum value. Formula: Range = Max - MinExample: For data: [2, 1, 2, 5, 100] Range: 100 - 1 = 99 So, the range is 99. ๐Ÿ“Œ Range gives a quick idea of spread, but it is highly affected by outliers.
    6.4 ๐Ÿ“Š Variance
    1. Variance tells us how spread out 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
Same Mean, Different Variance
Same Mean, Different Variance
    6.5 ๐Ÿ“‰ Standard Deviation
    1. Standard deviation is the square root of variance. Formula: Standard Deviation = โˆšVariance Standard deviation is easier to understand than variance because it is in the same unit as the original data. ๐Ÿ“Œ Standard deviation tells us how much values usually differ from the average.

7. Example: Dispersion Calculation

    7.1 Given Data
    1. For data points [5, 20, 95]: Mean: (5 + 20 + 95) / 3 = 120 / 3 = 40 Minimum: 5 Maximum: 95 Range: 95 - 5 = 90
7.2 Variance and Standard Deviation Calculation
Value (X)Difference from Mean (X - Xฬ„)Squared Difference (X - Xฬ„)ยฒ
55 - 40 = -35(-35)ยฒ = 1225
2020 - 40 = -20(-20)ยฒ = 400
9595 - 40 = 55(55)ยฒ = 3025
Variance(1225 + 400 + 3025) / 3 = 1550
Standard Deviationsqrt(1550) = 39.37
Example showing calculation of Variance and Standard Deviation

8. Covariance and Correlation

    8.1 ๐Ÿ”— Why Do We Study Relationships Between Variables?
    1. 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
    8.2 ๐Ÿ”„ Covariance
    1. Covariance tells us whether two variables move together. Formula: Cov(X, Y) = ฮฃ((Xi - Xฬ„)(Yi - ศฒ)) / N
Covariance Types
TypeDescriptionExample
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
    8.3 ๐Ÿ“ˆ Correlation
    1. Covariance tells us the direction of a relationship, but not how strong it is. Correlation tells us both: โœ… Direction of relationship โœ… Strength of relationship Correlation always lies between -1 and +1. Formula: Correlation = Cov(X, Y) / (Std(X) ร— Std(Y))
Interpretation of Correlation Values
CorrelationMeaning
+1Perfect Positive Correlation: Both variables increase together.
-1Perfect Negative Correlation: One variable increases while the other decreases.
0No or Very Weak Correlation: No clear relationship between the two variables.
0.5Moderate Positive Correlation: As one variable increases, the other tends to increase moderately.
Interpretation of Correlation Values
Plot showing examples of Positive, Negative and Zero Correlation

9. Example: Covariance and Correlation Calculation

    9.1 Given Data
    1. X = [5, 20, 95] Y = [10, 30, 50] Mean of X: Xฬ„ = (5 + 20 + 95) / 3 = 40 Mean of Y: ศฒ = (10 + 30 + 50) / 3 = 30
9.2 Calculation table of Covariance and Correlation
XX - Xฬ„(X - Xฬ„)ยฒYY - ศฒ(Y - ศฒ)ยฒ(X - Xฬ„) * (Y - ศฒ)
55 - 40 = -35(-35)ยฒ = 12251010 - 30 = -20400(-35) * (-20) = 700
2020 - 40 = -20(-20)ยฒ = 4003030 - 30 = 00(-20) * (0) = 0
9595 - 40 = 5555ยฒ = 30255050 - 30 = 2040055 * 20 = 1100
Example showing calculation of Covariance and Correlation
    Calculations
    1. Var(X) = (1225 + 400 + 3025) / 3 = 4650 / 3 = 1550 Var(Y) = (400 + 0 + 400) / 3 = 800 / 3 = 266.67 Cov(X, Y) = (700 + 0 + 1100) / 3 = 1800 / 3 = 600 Std(X) = โˆš1550 = 39.37 Std(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.

10. Spearman Rank Correlation

    10.1 ๐Ÿ† What is Spearman Rank Correlation?
    1. 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))
    10.2 Calculation Example
    1. T-shirt Size = ['M', 'S', 'L', 'XL'] Customer Satisfaction = [3, 4, 2, 5]
Spearman Rank Correlation for T-shirt Size and Satisfaction
T-shirt SizeRank T-shirt (R1)SatisfactionRank Satisfaction (R2)d = R1 - R2dยฒ
M2322 - 2 = 00ยฒ = 0
S1431 - 3 = -2(-2)ยฒ = 4
L3213 - 1 = 22ยฒ = 4
XL4544 - 4 = 00ยฒ = 0
Ranking and calculation of Spearman correlation
    Ranking Table
    1. 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. Calculationn = 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.

11. Probability

    11.1 ๐ŸŽฒ What is Probability?
    1. Probability tells us how likely something is to happen. It is a number between 0 and 1. Interpretation: 0 โžœ Impossible 0.5 โžœ 50% chance 1 โžœ Certain โ˜” Simple Example If a weather app says: Probability of rain = 0.8 It means there is an 80% chance of rain, so carrying an umbrella is a smart choice.
    11.2 Probability Formula
    1. P(A) = Number of favorable outcomes / Total number of outcomesExample: If a coin is flipped, possible outcomes are: Head, Tail Probability of getting Head: P(Head) = 1 / 2 = 0.5 So, there is a 50% chance of getting Head.
Probability Scale
Probability Scale
    11.3 Basic Probability Rules
    1. Rule 1: Event and Not Event P(A) + P(not A) = 1 Example: If probability of rain is 0.8: P(no rain) = 1 - 0.8 = 0.2Rule 2: A or B P(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.
Ad PlaceholderSlot: 7421026683

Practice QuestionsNot started

  1. Central Tendency

    Question 1 of 2

    • Write a function calc_mean that takes a list of numbers and returns mean.
    • Write a function calc_median that takes a list of numbers and returns median.
    • Write a function calc_mode that 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.
  2. Dispersion

    Question 2 of 2

    • Write a function calc_range that takes a list of numbers and returns range using max_value - min_value.
    • Write a function calc_covariance that takes two lists of numbers and returns covariance.
    • Write a function calc_variance that takes a list of numbers and returns variance. Hint: You can calculate variance as calc_covariance(x, x)
    • Write a function calc_correlation that takes two lists of numbers and returns correlation. Note: Re-use calc_covariance and calc_variance functions. Standard deviation can be calculated as sqrt(variance).
    • Test functions with the datasets X = [5, 20, 95] and Y = [10, 30, 50]. Verify range(X) = 90, covariance = 600, Var(X) = 1550, Correlation = 0.93.
    • Write a function calc_bmi that takes height (in meters) and weight (in kg) and returns BMI. bmi = weight / (height * height). Test this function for height list [1.6, 1.7, 1.8] and weight list [50, 70, 90]. Verify BMI values are approximately [19.53, 24.22, 27.78].
Ad PlaceholderSlot: 5413242224