Day - 2
1. Measures of Central Tendency & Spread
These form the foundation for understanding skewness, distribution shape, and sampling techniques.
Central Tendency
These measure the “center” of a dataset.
Mean (Average)
• Add all values ÷ number of values.
• Highly sensitive to outliers (because a single extreme value pulls the mean heavily).
Median (Middle value)
• 50% values below, 50% above.
• Robust to outliers — a few extremely large or small values barely shift the median.
Mode (Most frequent value)
• Good for identifying recurring behavior or dominant groups.
Spread Measures
These describe variability.
Range
• Max − Min
• Very sensitive to outliers.
Variance
• Average squared deviation from mean.
Standard Deviation (SD)
• Square root of variance.
• Higher SD → data more spread out.
IQR (Interquartile Range)
• Q3 − Q1
• Excellent for identifying outliers (using 1.5×IQR rule).
Mean–Median–Mode Relationship & Skewness
This trio helps infer distribution shape:
• Mean > Median > Mode → Right skew
○ Long tail on right
○ Example: income data
• Mean < Median < Mode → Left skew
○ Long tail on left
○ Example: exam scores when many top performers
• Mean = Median = Mode → Normal distribution
○ Perfect symmetry
Effect of Outliers
• Outliers pull the mean significantly.
Session notes Page 1
• Outliers pull the mean significantly.
• Median barely shifts.
Thus, whenever data has extreme values, median is more trustworthy for describing “typical” behavior.
2. Skewness & Kurtosis
These quantify shape beyond center and spread.
Skewness
Measures the direction and degree of asymmetry.
Positive (Right) Skew
• Long tail on the right
• Mean > Median
• Many low values, few very high values
• Examples: income, hospital bills
Negative (Left) Skew
• Long tail on left
• Mean < Median
• Many high values, few very low values
• Examples: easy test scores
Zero Skew
• Perfect symmetry
• Mean = Median = Mode
Interpretation rule:
→ Skew sign tells where the tail is.
Kurtosis
Measures tail thickness and outlier frequency.
Session notes Page 2
Leptokurtic (High Kurtosis > 3)
• Heavy tails
• Many extreme values
• “Peaky center + fat tails”
Platykurtic (Low Kurtosis < 3)
• Light tails
• Fewer outliers
• Flatter distribution
Mesokurtic (≈ 3)
• Normal-like behaviour
What High Kurtosis Means
• Extreme values more common
• Risk of outliers is high
• Mean becomes unreliable
• Requires robust statistical treatment
Combine Histogram + Stats
When both agree (histogram shows tail + skew/kurt confirm), interpretation is reliable.
3. Distribution Shapes
Students must classify distributions simply by looking at stats and plots.
Normal / Gaussian
• Symmetric bell curve
• Mean = Median = Mode
• Used heavily in statistical inference
Skewed
• Asymmetrical
• Right-skewed: long right tail
• Left-skewed: long left tail
Uniform
• Flat
• All values equally likely
Bimodal / Multimodal
• Multiple peaks
• Indicates subpopulations or mixed behavior
Session notes Page 3
• Indicates subpopulations or mixed behavior
Unimodal
• One peak
• Most real business data is unimodal but skewed
Relationship Between Shape & Central Tendency
• Shape determines how far mean shifts from median.
• Shape also dictates choice of model, test, sampling method.
4. Sampling Methods
Simple Random Sampling (SRS)
• Every element has equal chance
• Good for general-purpose sampling
• Fails when population is imbalanced (e.g., gender ratio mismatch)
Stratified Sampling
• Divide population into strata (like gender, region, category)
• Draw samples proportionally or equally from each.
Why use it?
• Ensures representation
• Must use when population has important subgroups
• Most reliable for fairness/accuracy
Systematic Sampling
• Pick every k-th item (e.g., every 5th customer)
• Fast and easy
• Risk: if data is periodic, sample becomes biased
Cluster Sampling
• Divide population into clusters (e.g., towns, schools)
• Randomly pick some clusters
• Sample everyone inside those clusters
Risk:
• Clusters may not be representative
• Intra-cluster similarity reduces diversity
Key Differences
• Stratified sampling ensures representation by sampling from every subgroup.
• Cluster sampling reduces cost by sampling a few whole groups.
Stratified Sampling Example
You’re studying average height in a school.
Strata: 6th grade, 7th grade, 8th grade.
You sample some students from each grade.
Result → balanced, accurate.
Cluster Sampling Example
Same school, but resources are limited.
Clusters: classrooms.
Session notes Page 4
Clusters: classrooms.
You randomly choose two classrooms and survey all students in them.
Result → cheap, but maybe less representative.
5. Central Limit Theorem (CLT)
Definition
Regardless of population shape, if we repeatedly take sufficiently large random samples (n ≥ 30),
the distribution of sample means becomes approximately normal.
Why CLT Matters
• Allows inference even on messy data
• Enables confidence intervals, hypothesis tests
• Makes “mean” a stable quantity
CLT Conditions
1. Sampling must be random
2. Sampling must be independent
3. Sample size must be ≥ 30 (rule of thumb)
4. Population shape doesn’t matter (skew okay)
Behavior of Sample Means
• Mean of sample means ≈ population mean
• Standard deviation of sample means = Standard Error (SE)
• SE = σ / √n
• As n increases:
○ SE decreases
○ Sampling distribution becomes narrower and more normal
CLT on Skewed Populations
• For skewed populations:
○ Small samples (n < 30) → sampling distribution still skewed
○ Large samples → sampling distribution becomes symmetric
[Link] Distribution — The Engine Behind Statistical Inference
Definition
A sampling distribution is the probability distribution of a statistic
(mean, median, proportion, variance)
calculated from many random samples of the same size drawn from the population.
Intuition
You take:
• Sample 1 → compute mean
• Sample 2 → compute mean
• Sample 3 → compute mean
• … repeat 1000+ times
Now put all these sample means together.
That distribution = sampling distribution of the sample mean.
Key Properties
1. Centered at the population mean (μ)
The average of all sample means ≈ μ.
2. Has lower spread than population
Sample means vary less than individual data points.
3. Shape becomes normal (Central Limit Theorem)
Even if population is skewed → sampling distribution of means becomes approximately normal when sample size ≥ 30.
Standard Error (SE) — The Precision Metric
Definition
Standard Error (SE) measures the spread (variability) of the sampling distribution of a statistic.
For sample mean:
Session notes Page 5
If population standard deviation is unknown, use sample SD:
Interpretation
• SE is not the same as standard deviation.
• SD = variability of raw data.
• SE = variability of sample means.
Why SE matters
• It quantifies how much the sample mean fluctuates across samples.
• Smaller SE = more reliable estimate of the population mean.
Relationship Between Sampling Distribution & Standard Error
Concept Meaning Relationship
Sampling Distribution Distribution of sample means SE = SD of this distribution
Standard Error Spread of sampling distribution Smaller SE → narrower sampling distribution
Sample Size (n) Number of data points in each sample Larger n → smaller SE → narrower distribution
As n increases:
• Sampling distribution becomes tight and normal.
• Standard error shrinks.
• Sample mean becomes more accurate.
This is why larger samples reduce uncertainty.
Visual Mental Model
Imagine throwing darts:
• Population SD → how widely darts scatter anywhere on the board.
• Standard Error → how much the centers of groups of darts move around.
If you take groups of 5 throws:
• The group-centers wander a lot → large SE.
If you take groups of 50 throws:
• Each group’s center is very close to true average → small SE.
Numerical Example
Population standard deviation: σ = 10
n = 25
n = 100
→ When you 4× the sample size, SE reduces by half.
7. Visual Interpretation of Distributions
Many exam questions combine plots + summary statistics.
Histogram
• Shows the shape of raw data
• Identifies skewness, outliers, modes
KDE (Kernel Density Estimate)
• Smooth representation of distribution
• Good for identifying modality
Confirming Skewness
• Long right tail + mean > median = right skew
• Long left tail + mean < median = left skew
Session notes Page 6
• Long left tail + mean < median = left skew
Identifying Modality
• KDE peak count = number of modes
• Histogram reveals lumps in data
Histogram + Stats Combo
• Visual shape + numerical skew/kurtosis → complete story
Skewness Value Type of Skew Interpretation
< -0.5 Left-skewed (negative) Tail is extended to the left; most data lies to the right
-0.5 to +0.5 Approximately symmetric No significant skew; mean ≈ median
> +0.5 Right-skewed (positive) Tail is extended to the right; most data lies to the left
Kurtosis Value Type Interpretation
<0 Platykurtic Flatter than normal; lighter tails, fewer outliers
≈0 Mesokurtic Similar to normal distribution (benchmark kurtosis = 0)
>0 Leptokurtic More peaked than normal; heavier tails, more outliers
Summary
• Measures of Central Tendency & Spread
• Spread Measures
• Skewness & Kurtosis
• Distribution Shapes
• Sampling Methods
• Central Limit Theorem (CLT)
• Sampling Distribution
• Standard Error
• Visual Interpretation of Distributions - Histogram, KDE
Session notes Page 7
Day - 3
1. Formulating Hypotheses (H₀ & H₁)
Hypothesis testing always starts with identifying the claim and assigning it correctly.
Null hypothesis (H₀)
A statement of no change, no effect, or status quo.
Examples:
Alternative hypothesis (H₁ / Hₐ)
Represents the claim being tested.
Three possible forms of H₁
Beginner
# 1. A company claims its average delivery time is ≤ 3 days. Formulate H₀ and H₁.
μ ≤ 3
μ > 3
# 2. A nutrition bar states it contains 20g of protein. A student suspects it is less. Formulate hypotheses.
μ ≥ 20
μ < 20
# Intermediate
# 1. A hospital claims the average wait time for emergency patients is no more than 25 minutes. A watchdog disagrees—
frame the hypotheses.
"H0": "μ ≤ 25", "H1": "μ > 25"
# 2. A smartphone brand states its average battery life is 18 hours. Competitors allege it's inflated. Formulate
hypotheses.
"H0": "μ ≥ 18", "H1": "μ < 18"
# Q1.1
print("Q1.1 Company claims avg delivery time ≤ 3 days.")
print("A:", {"H0": "μ ≤ 3", "H1": "μ > 3"})
# Q1.2
print("\nQ1.2 Protein claim = 20g, suspect less.")
print("A:", {"H0": "μ ≥ 20", "H1": "μ < 20"})
2. Understanding p-Value (the core decision metric)
Definition
The p-value is the probability of observing a result as extreme as the sample, IF H₀ is true.
Interpretation
• Small p-value → strong evidence against H₀
• Large p-value → sample is consistent with H₀
Decision Rule
• If p < α, reject H₀
• If p ≥ α, fail to reject H₀
Tail logic
• Right-tailed → area to right of Z
• Left-tailed → area to left of Z
• Two-tailed → double the one-sided area
p-value range Meaning
0 ≤ p < 0.01 Very strong evidence against H₀
0.01 ≤ p < 0.05 Strong evidence against H₀
0.05 ≤ p < 0.10 Weak evidence against H₀
p ≥ 0.10 Insufficient evidence to reject H₀
Session notes Page 8
# Beginner
# 1. If p = 0.08 and α = 0.05, what is the decision?
Fail to reject H0
# 2. p = 0.001. What does this imply about evidence against the null?
Very strong evidence against H0
# Intermediate
# 1. A test yielded p = 0.049 at α = 0.05. Interpret precisely.
# 2. A researcher obtains p = 0.20. What two explanations could cause high p-value?
"Data consistent with H0", "Low sample size → low power"
3. Z-Test Fundamentals
Z-statistic formula
When to use Z-test
• Population SD known (σ known)
• Large sample size (n ≥ 30)
Types
Z-Test Usage
One-sample Z-test Sample mean vs population mean
Two-sample Z-test Difference of two independent means with known σ’s
Two-sample Z-test formula
Step 1: State hypotheses
Step 2: Compute Z-statistic
Step 3: Choose significance level
Step 4: Get Z-critical from table
α (significance) Test Type Z-critical
0.10 One-tailed 1.28
0.05 One-tailed 1.645
0.01 One-tailed 2.33
0.10 Two-tailed ±1.645
0.05 Two-tailed ±1.96
0.01 Two-tailed ±2.576
Step 5: Apply rejection rule
Step 6: Write conclusion
With p value
Step 1: State hypotheses
Step 2: Compute Z-statistic
Step 3: Compute p-value
Step 4: Compare with α
Step 5: Conclusion
Interpretation of Z
Large |Z| → sample mean far from μ₀ → evidence against H₀.
Session notes Page 9
# Population σ = 10, n = 100, sample mean = 53, μ₀ = 50 → compute Z.
z = (53 - 50) / (10 / [Link](100))
# When do we use Z-test? List two conditions.
"σ known", "large n (>=30)"
# Intermediate
# σ = 15, n = , = 112, ₀ = 100. ompute Z and interpret.
# manu acturer claims μ = 250. ample = 255, → two tailed test at = 0.01. ould we re ect
z = (112 - 100) / (15 / [Link](64))
print("\nQ3.5 Z =", round(z, 2))
# Q3.6
z = (255 - 250) / (20 / [Link](25))
print("\nQ3.6 Z =", round(z, 2), "→ Fail to re ect at =0.01")
4. t-Test Fundamentals
When t-test is required
• Population SD unknown
• Sample size < 30
• Data roughly normal
Step 1: State hypotheses
Step 2: Compute t-statistic
Step 3: Degrees of freedom (df)
Step 4: Get t-critical
Step 5: Rejection rule
Step 6: Conclusion
Types
t-Test Usage
One-sample t-test Compare sample mean vs μ₀ when σ unknown
Two-sample independent t-test Compare two group means
Paired t-test Before–after, same individuals
One-sample t formula
Two-sample t formula
Paired t-test logic
Session notes Page 10
5. Confidence Intervals (CIs) and Interpretation
Confidence intervals add context to hypothesis testing.
General Form
Meaning of a 95% CI
• If we repeat sampling 100 times, 95 intervals will contain the true mean.
Interpretation with Hypothesis Testing
• If μ₀ falls inside the CI → fail to reject H₀
• If μ₀ falls outside the CI → reject H₀
Z-based CI (σ known)
t-based CI (σ unknown)
6. Critical Values & Rejection Regions
Critical value = threshold beyond which we reject H₀.
Common Z critical values
Session notes Page 11
Confidence Level (CI) α α/2 tₐ/₂ (≈ z)
90% 0.10 0.05 1.645
95% 0.05 0.025 1.96
98% 0.02 0.01 2.33
99% 0.01 0.005 2.576
Decision rule using critical value
• If statistic lies inside rejection region → reject H₀
7. Standard Error (SE) & Sampling Distribution
Formula
Meaning
SE measures expected variability in sample means across samples.
Connection to CLT
• As n increases, sample mean becomes normally distributed.
• Justifies using Z-test for large samples.
8. One-tailed vs Two-tailed Tests (Choosing Direction)
Triggers for RIGHT-tailed
• “increase”
• “more”
• “higher”
• “greater than”
Triggers for LEFT-tailed
• “decrease”
• “lower”
• “reduced”
Triggers for TWO-tailed
• “different”
• “changed”
• “effect”
• “impact”
9. Test Selection Framework
Situation Correct Test
σ known, large n One-sample Z-test
σ known, two groups Two-sample Z-test
σ unknown, n < 30 One-sample t-test
Two independent groups, σ unknown Two-sample t-test
Before–after same subjects Paired t-test
CI with σ known Z-CI
CI with σ unknown t-CI
10. Type I & Type II Errors (Simple & Crucial)
Type I Error (α)
Rejecting a true H₀
= False positive
Type II Error (β)
Failing to reject a false H₀
= False negative
Session notes Page 12
= False negative
Final Integrated Insight
Everything in hypothesis testing reduces to three pillars:
1. Correctly formulating H₀ and H₁
(determines direction and test type)
2. Choosing Z-test or t-test based on σ known and sample size
3. Making decisions via p-value or confidence interval
_____________________________________________________________
1. Formulating Hypotheses (H₀ & H₁)
2. Understanding p-Value
3. Z-Test Fundamentals
4. t-Test Fundamentals
5. Confidence Intervals (CIs) and Interpretation
6. Critical Values & Rejection Regions
7. Standard Error (SE) & Sampling Distribution
8. One-tailed vs Two-tailed Tests
9. Type I & Type II Errors
Session notes Page 13
Day - 4
1. Nature and properties of chi-square distribution
2. Degrees of freedom and χ² critical values
3. Assumptions for all chi-square tests
4. Goodness-of-Fit test theory
5. Goodness-of-Fit expected frequency calculations
6. Python: [Link]()
7. Chi-Square Test of Independence theory
8. Building and interpreting contingency tables
9. Expected frequency formula for independence
10. Python: [Link].chi2_contingency()
11. Chi-Square Test of Homogeneity theory
12. Distinguishing Independence vs. Homogeneity
13. Identifying correct test from real-world scenarios
14. Hypotheses for GOF, independence, homogeneity
15. Interpreting χ² statistic
16. Interpreting p-value
17. Interpreting critical values
18. Reject vs. fail-to-reject logic
19. Computing cell-wise contribution
20. Business applications across BFSI, retail, OTT, telecom
21. Identifying wrong tests (t-test, z-test, ANOVA) for categorical data
22. Multi-category, multi-group comparison logic
23. Ratio-based expected frequency calculations
24. Uniform distribution assumptions
25. How to conclude with statistical significance
Test Null Hypothesis (H_0) Alternative (H_1)
GOF Observed distribution = expected distribution Observed ≠ expected
Independence Variables are independent Variables are associated
Z-test Population mean = hypothesized mean ≠, >, or <
t-test Same as Z, but σ unknown ≠, >, or <
Chi-Square Test of Independence
Topic Core Purpose
Chi-Square GOF Test if one variable’s distribution matches an expected pattern.
GOF Hands-On Build operational skill to compute & interpret GOF.
Chi-Square Independence Test if two categorical variables are associated.
Independence Hands-On Build ability to compute associations & interpret contingency tables.
⭐ MODULE 1 — Foundations of Chi-Square Analysis
Covers:
1. Nature & properties of the chi-square distribution
2. Degrees of freedom & χ² critical values
3. Assumptions for all chi-square tests
ature and Proper es of t e C i S uare Distribu on
Intuition (How to feel the concept)
Imagine you’re checking how far reality deviates from expectation.
Chi-square measures “ ow muc mismatc exists between observed vs expected counts.”
If the mismatch is:
• Small → distributions align → χ² small
• Large → distributions differ → χ² large
Because mismatch cannot be negative, χ² is:
• Always ≥ 0
• Right-skewed (small values are common; large values rare)
Formal Definition
A chi-square distribution is the distribution of a sum of squared standardized values:
Session notes Page 14
Used for:
• Goodness-of-Fit
• Independence
• Homogeneity
• Variance tests (less common)
Mathematical Understanding
Shape properties:
• Skew decreases as degrees of freedom increase
• Mean = df
• Variance = 2 × df
Why squares?
Because any deviation (positive or negative) must count as “misfit.”
Squaring ensures:
• no cancellations
• large deviations get heavily penalized
Python Code — Visualizing the Distribution
import numpy as np
import [Link] as plt
from [Link] import chi2
x = [Link](0, 20, 500)
[Link](x, [Link](x, df=3), label='df=3')
[Link](x, [Link](x, df=6), label='df=6')
[Link](x, [Link](x, df=10), label='df=10')
[Link]()
[Link]("Chi-Square Distribution for Different Degrees of Freedom")
[Link]()
Real-Time Example — OTT User Engagement
You expect monthly engagement for a movie genre to be uniform across 12 months.
If reality perfectly matches expectation → χ² ≈ 0.
But if January is 5× higher and other months are lower → χ² becomes huge → mismatch detected.
Conclusion
Chi-square is a right-skewed, non-negative distribution that quantifies how far observed categorical data deviates from expectations. It is the mathematical engine behind categorical hypothesis testing.
Degrees of reedom (df) and C i S uare Cri cal alues
Intuition
df = “how many categories are free to vary after accounting for constraints.”
Example:
If total = 100 and you know 3 category counts, the 4th is forced — not free.
df determines:
• how wide or narrow the chi-square distribution is
• what critical value you must compare against
Formal Definition
Goodness-of-Fit
df=k−1
where k = number of categories.
Independence / Homogeneity
df=(r−1)(c−1)
where r = rows, c = columns.
Mathematical Understanding
Higher df → curve shifts right → critical values increase.
Example critical values (α=0.05):
df χ² critical
1 3.841
2 5.991
3 7.815
6 12.59
12 21.026
Large χ² > critical → data contradicts expectation.
Python Code — Getting Critical Value
from [Link] import chi2
df = 6
critical = [Link](0.95, df)
print(critical)
Real-Time Example — BFSI Fraud Detection
A bank wants to check if fraud frequency across 4 branches follows expected ratios.
• Categories = 4
Session notes Page 15
• Categories = 4
• df = 3
• χ² critical = 7.815
If χ² = 12.1 → exceeds → fraud pattern differs → escalate investigation.
Conclusion
df controls the decision threshold.
Without df, you cannot compute critical values or p-values.
ssump ons for ll C i S uare ests
Intuition
Chi-square tests rely on comparing expected vs observed counts.
For this to be meaningful, data must follow certain structure.
Formal Requirements
ata must be categorical
No means, no continuous values.
bserva ons must be independent
No person counted twice.
E pected fre uency ≥ per cell
Ensures accuracy of chi-square approximation.
ample size must be reasonably large
Rule of thumb: N ≥ 30.
Random sampling is preferred
Avoids bias.
Mathematical Justification
The chi-square test relies on the Central Limit Theorem (categorical version):
When expected counts are ≥5, the distribution of deviations approaches chi-square.
Cells with expected <5 distort the distribution → must be merged.
Python Code — Checking Assumptions
import numpy as np
expected = [Link]([12, 8, 15, 3]) # example
if (expected < 5).any():
print("Warning: Expected frequency < 5 — chi-square not reliable.")
else:
print("Assumptions satisfied.")
Real-Time Example — Retail Product Preferences
A retailer checks preference across 6 brands.
If one brand sells only 2 pieces → expected < 5 → merge categories or use Fisher’s exact test.
Conclusion
Assumptions ensure chi-square results are statistically valid, not artifacts of small or biased data.
✅ MODULE 1 Summary
You now understand:
• What χ² distribution represents
• How degrees of freedom shape the test
• The core assumptions enabling valid chi-square inference
⭐ MODULE 2 — Chi-Square Goodness-of-Fit (GOF)
Covers:
4. GOF Theory
5. Expected Frequency Calculations
6. Python: [Link]()
C i S uare oodness of it ( ) est eor
Intuition (What problem does GOF solve?)
GOF answers one fundamental question:
“Does the observed categorical distribution match the distribution we expected?”
Examples:
• Should sales across 4 quarters be equal?
• Should user engagement be uniform across 12 months?
• Should T-shirt sizes be equally preferred?
• Should customer sentiment follow a 3:2:1 ratio?
You have ONE categorical variable, and you want to see whether the pattern (distribution) aligns with expectations.
If the mismatch is small → expectation is correct.
If the mismatch is large → something structurally different is happening.
Formal Definition
GOF compares:
• Observed frequencies: what happened
• Expected frequencies: what should happen under H₀
The test statistic is:
Session notes Page 16
The test statistic is:
Hypotheses:
• H₀: Observed distribution matches expected distribution
• H₁: Observed distribution differs (at least one category mismatches)
Mathematical Understanding
Each term:
Large χ² → big mismatch; small χ² → good alignment.
Unlike t/z tests, chi-square uses squared differences scaled by expectation, not means or variances.
Python — Running the GOF Test
Example:
Observed = [90, 110, 95, 105, 100]
Expected = equal preference among 5 brands
from [Link] import chisquare
observed = [90, 110, 95, 105, 100]
expected = [100, 100, 100, 100, 100]
stat, p = chisquare(f_obs=observed, f_exp=expected)
print(stat, p)
Real-Time Example — OTT / Streaming Case
Scenario:
StreamFlix assumes monthly engagement for the “Action” genre is uniform.
Total yearly engagement = 38,260
Number of months = 12
Expected per month = 3188.33
Given observed array:
obs = [4672, 3201, 2989, ...] # 12 values
exp = [38260/12] * 12
chisquare(obs, exp)
Interpretation:
• If p < 0.05 → engagement is NOT uniform
• If p > 0.05 → uniform distribution assumption holds
This directly reveals seasonality, holiday surges, etc.
Conclusion
GOF tells you whether your expected distribution model is valid.
It’s the statistical firewall against wrong assumptions.
xpected re uenc Calcula ons for
Expected values depend on what H₀ says.
Intuition
Expected = “What should we see if the assumption is correct?”
Two types:
Type A — Uniform expectation
Equal probability for all categories.
Type B — Ratio/Proportion-based expectation
E.g., expected ratios = 3:2:1
Conclusion
Expected values operationalize your hypothesis.
If they’re wrong, the entire test collapses. GOF is only as good as the expected distribution you choose.
Session notes Page 17
If they’re wrong, the entire test collapses. GOF is only as good as the expected distribution you choose.
P t on scip .stats.c is uare() xplained
Intuition
chisquare() implements Goodness-of-Fit:
• You provide observed and expected arrays
• It compares category-by-category
• Returns statistical proof of match/mismatch
Function Definition
chisquare(f_obs, f_exp=None)
• f_obs → observed counts
• f_exp → expected counts (if None = uniform assumption)
Returns:
• statistic → χ² value
• pvalue → probability of seeing this mismatch by chance
Python Example — Airline Meal Preferences
from [Link] import chisquare
observed = [240, 210, 90, 60] # Veg, Non-Veg, Vegan, Keto
expected = [150, 150, 150, 150] # equal uptake assumption
stat, p = chisquare(observed, expected)
print("Chi2:", stat, "p:", p)
Interpretation:
• If p < 0.05 → assume NOT equal uptake
• If p > 0.05 → equal uptake assumption stands
Business Example — BFSI Branch Fraud Cases
Branches: A, B, C, D
Observed frauds = [50, 40, 30, 20]
Bank assumes equal fraud probability.
Expected = [35, 35, 35, 35]
stat, p = chisquare([50,40,30,20], [35]*4)
print(stat, p)
If p < 0.05 → some branch significantly deviates → investigate fraud patterns.
Conclusion
chisquare() is the operational tool for validating distribution assumptions in any business with categorical data: retail, BFSI, telecom, OTT, healthcare.
⭐ MODULE 2 Summary
You now deeply understand:
• What GOF tests
• How expected frequencies work
• How to run GOF in Python
• How to interpret the results
• Real-world strategic applications
⭐ MODULE 3 — Chi-Square Independence + Contingency Tables + Expected Frequencies + chi2_contingency()
C i S uare est of Independence eor
Intuition (What question does it answer?)
The test of independence answers:
“Are two categorical variables related or independent?”
Example:
• Does age group influence service preference?
• Does city influence payment mode?
• Does training regimen influence player performance?
• Does loan type influence default risk?
This test is used when you have two categorical variables and want to know whether patterns in one depend on the other.
If patterns align → independent.
If patterns differ → dependent (relationship exists).
Formal Definition
We build a contingency table (r × c) and compare:
• Observed counts
• Expected counts under independence
Hypotheses:
• H₀: Variables are independent
• H₁: Variables are dependent
Python — Running Independence Test
Session notes Page 18
import numpy as np
from [Link] import chi2_contingency
table = [Link]([
[40, 60], # students choosing domestic vs international
[90, 60], # professionals
[70, 30], # retired
])
chi2, p, df, expected = chi2_contingency(table)
print(chi2, p, df)
print(expected)
Real-Time Example — Telecom Company
Survey variables:
• Age Group: 18-25, 26-35, 36-50
• Service Preference: Prepaid, Postpaid
Contingency table:
Age Group Prepaid Postpaid
18–25 100 50
26–35 120 80
36–50 90 110
Compute chi-square.
If p < 0.05 → service preference depends on age group.
If p > 0.05 → no dependency.
Conclusion
Chi-square independence is the workhorse for analyzing categorical associations in marketing, BFSI, telecom, HR, and healthcare.
uilding and Interpre ng Con ngenc ables
Intuition
A contingency table represents frequency counts of combinations of categories.
Example:
Gender Bought Not Bought
Male 40 60
Female 50 50
Rows = categories of variable 1
Columns = categories of variable 2
Formal Definition
A contingency table is an r × c matrix of joint frequencies:
Interpreting the Table
Look for:
• Row patterns
• Column patterns
• Cross-cell differences
But raw differences are misleading—statistical testing is needed.
Python Code — Constructing a Table
import pandas as pd
df = [Link]({
"Age": ["18-25","18-25","26-35","36-50"],
"Service": ["Prepaid","Postpaid","Prepaid","Postpaid"]
})
[Link](df["Age"], df["Service"])
Real Example — Retail Clothing Preference Across Cities
City Casual Formal Sportswear
Pune 40 30 30
Ahmedabad 35 35 30
Kolkata 45 25 30
This matrix becomes the input to chi2_contingency().
Conclusion
Contingency tables convert raw data into structured buckets where chi-square can measure deviation from independence.
xpected re uenc ormula (Independence)
Intuition
Expected values show what the table should look like if no association exists.
Formula:
This allocates counts proportionally assuming independence.
Example Calculation
Given:
Yes No Total
Session notes Page 19
Yes No Total
Male 40 60 100
Female 50 50 100
Total 90 110 200
Python Code — Manually Compute Expected
import numpy as np
table = [Link]([[40, 60], [50, 50]])
row_totals = [Link](axis=1)
col_totals = [Link](axis=0)
grand_total = [Link]()
expected = [Link](row_totals, col_totals) / grand_total
print(expected)
Real Example — Airline Meal Preferences by Flight Class
Cabin classes: Economy, Business
Meals: Veg, Non-Veg
Veg Non-Veg Total
Economy 200 150 350
Business 40 10 50
Total 240 160 400
Conclusion
Expected frequencies allow chi-square to quantify whether the actual table is too different from what independence predicts.
Python: [Link].chi2_contingency()
Intuition
This function performs:
• Chi-square test
• Computes expected frequencies
• Computes p-value
• Checks relationship between categories
One function solves the entire independence/homogeneity problem.
Function Definition
chi2_contingency(observed)
Returns:
1. chi2 statistic
2. p-value
3. df
4. expected matrix
Mathematical Work Done Internally
It:
1. Computes row totals
2. Computes column totals
3. Calculates expected frequencies
4. Computes chi-square
5. Computes p-value using df
Python Code — Example
import numpy as np
from [Link] import chi2_contingency
observed = [Link]([
[30, 10, 10], # Mumbai
[25, 15, 10], # Delhi
[20, 20, 10] # Bangalore
])
chi2, p, df, expected = chi2_contingency(observed)
print("Chi2:", chi2)
print("p:", p)
print("df:", df)
print("Expected:\n", expected)
Real Example — BFSI Payment Mode Across Cities
Session notes Page 20
Real Example — BFSI Payment Mode Across Cities
Cities: Mumbai, Delhi, Bangalore
Modes: UPI, Card, NetBanking
Same example as file:
Observed:
City UPI Card NetBanking
Mumbai 30 10 10
Delhi 25 15 10
Bangalore 20 20 10
If p = 0.33 > 0.05 → fail to reject H₀ → payment mode preference same across cities.
Conclusion
chi2_contingency() is the backbone of analyzing relationships in two-dimensional categorical data. It powers insights in BFSI segmentation, telecom churn, e-commerce behavior, and OTT preferences.
⭐ MODULE 3 Summary
You now understand:
• How independence works
• How contingency tables are built and interpreted
• How expected values under independence are computed
• How to run the test using Python
• How to conclude dependence vs independence
⭐ MODULE 3 — Chi-Square Independence + Contingency Tables + Expected Frequencies + chi2_contingency()
C i S uare est of Independence eor
Intuition (What question does it answer?)
The test of independence answers:
“Are two categorical variables related or independent?”
Example:
• Does age group influence service preference?
• Does city influence payment mode?
• Does training regimen influence player performance?
• Does loan type influence default risk?
This test is used when you have two categorical variables and want to know whether patterns in one depend on the other.
If patterns align → independent.
If patterns differ → dependent (relationship exists).
Formal Definition
We build a contingency table (r × c) and compare:
• Observed counts
• Expected counts under independence
Hypotheses:
• H₀: Variables are independent
• H₁: Variables are dependent
Mathematical Understanding
Expected frequencies under independence are calculated as:
This constructs the theoretical distribution if there is no relationship between variables.
If observed deviates significantly from this expected pattern → relationship exists.
Python — Running Independence Test
import numpy as np
from [Link] import chi2_contingency
table = [Link]([
[40, 60], # students choosing domestic vs international
[90, 60], # professionals
[70, 30], # retired
])
chi2, p, df, expected = chi2_contingency(table)
print(chi2, p, df)
print(expected)
Real-Time Example — Telecom Company
Survey variables:
• Age Group: 18-25, 26-35, 36-50
• Service Preference: Prepaid, Postpaid
Contingency table:
Age Group Prepaid Postpaid
18–25 100 50
26–35 120 80
36–50 90 110
Session notes Page 21
36–50 90 110
Compute chi-square.
If p < 0.05 → service preference depends on age group.
If p > 0.05 → no dependency.
Conclusion
Chi-square independence is the workhorse for analyzing categorical associations in marketing, BFSI, telecom, HR, and healthcare.
uilding and Interpre ng Con ngenc ables
Intuition
A contingency table represents frequency counts of combinations of categories.
Example:
Gender Bought Not Bought
Male 40 60
Female 50 50
Rows = categories of variable 1
Columns = categories of variable 2
Formal Definition
A contingency table is an r × c matrix of joint frequencies:
Oij=count of observations at row i and column jO_{ij} = \text{count of observations at row } i \text{ and column } jOij=count of observations at row i and column j
Interpreting the Table
Look for:
• Row patterns
• Column patterns
• Cross-cell differences
But raw differences are misleading—statistical testing is needed.
Python Code — Constructing a Table
import pandas as pd
df = [Link]({
"Age": ["18-25","18-25","26-35","36-50"],
"Service": ["Prepaid","Postpaid","Prepaid","Postpaid"]
})
[Link](df["Age"], df["Service"])
Real Example — Retail Clothing Preference Across Cities
City Casual Formal Sportswear
Pune 40 30 30
Ahmedabad 35 35 30
Kolkata 45 25 30
This matrix becomes the input to chi2_contingency().
Conclusion
Contingency tables convert raw data into structured buckets where chi-square can measure deviation from independence.
xpected re uenc ormula (Independence)
Intuition
Expected values show what the table should look like if no association exists.
Formula:
This allocates counts proportionally assuming independence.
Example Calculation
Given:
Yes No Total
Male 40 60 100
Female 50 50 100
Total 90 110 200
Python Code — Manually Compute Expected
import numpy as np
table = [Link]([[40, 60], [50, 50]])
Session notes Page 22
table = [Link]([[40, 60], [50, 50]])
row_totals = [Link](axis=1)
col_totals = [Link](axis=0)
grand_total = [Link]()
expected = [Link](row_totals, col_totals) / grand_total
print(expected)
Real Example — Airline Meal Preferences by Flight Class
Cabin classes: Economy, Business
Meals: Veg, Non-Veg
Veg Non-Veg Total
Economy 200 150 350
Business 40 10 50
Total 240 160 400
Conclusion
Expected frequencies allow chi-square to quantify whether the actual table is too different from what independence predicts.
Python: [Link].chi2_contingency()
Intuition
This function performs:
• Chi-square test
• Computes expected frequencies
• Computes p-value
• Checks relationship between categories
One function solves the entire independence/homogeneity problem.
Function Definition
chi2_contingency(observed)
Returns:
1. chi2 statistic
2. p-value
3. df
4. expected matrix
Mathematical Work Done Internally
It:
1. Computes row totals
2. Computes column totals
3. Calculates expected frequencies
4. Computes chi-square
5. Computes p-value using df
Python Code — Example
import numpy as np
from [Link] import chi2_contingency
observed = [Link]([
[30, 10, 10], # Mumbai
[25, 15, 10], # Delhi
[20, 20, 10] # Bangalore
])
chi2, p, df, expected = chi2_contingency(observed)
print("Chi2:", chi2)
print("p:", p)
print("df:", df)
print("Expected:\n", expected)
Real Example — BFSI Payment Mode Across Cities
Cities: Mumbai, Delhi, Bangalore
Modes: UPI, Card, NetBanking
Same example as file:
Observed:
City UPI Card NetBanking
Mumbai 30 10 10
Delhi 25 15 10
Bangalore 20 20 10
If p = 0.33 > 0.05 → fail to reject H₀ → payment mode preference same across cities.
Conclusion
chi2_contingency() is the backbone of analyzing relationships in two-dimensional categorical data. It powers insights in BFSI segmentation, telecom churn, e-commerce behavior, and OTT preferences.
⭐ MODULE 3 Summary
You now understand:
• How independence works
• How contingency tables are built and interpreted
Session notes Page 23
• How contingency tables are built and interpreted
• How expected values under independence are computed
• How to run the test using Python
• How to conclude dependence vs independence
⭐ MODULE 4 — Homogeneity, Independence, Test Selection, Hypotheses
C i S uare est of omogeneit eor
Intuition (The simplest way to feel the idea)
Independence:
Are two variables related?
(e.g., Age group ↔ service preference)
Homogeneity:
Do multiple groups follow the same distribution?
(e.g., Do three cities have the same clothing preference distribution?)
Homogeneity compares distributions across populations, not relationships between variables.
If distributions match → homogeneous (similar).
If not → heterogeneous (different).
Formal Definition
We compare the distribution of a single categorical variable across multiple populations:
• City A user preferences
• City B user preferences
• City C user preferences
Hypotheses:
• H₀: All populations share the same distribution
• H₁: At least one population’s distribution differs
(Same formula as independence, but meaning differs.)
Mathematical Understanding
Homogeneity treats each population as a sample from potentially different distributions.
The expected frequencies are computed in the same way as independence:
However, the question being answered is different:
• Independence: “Are variables associated?”
• Homogeneity: “Are groups similar in distribution?”
Python — Homogeneity Test Using chi2_contingency()
Yes, it's the same function as independence; interpretation differs.
import numpy as np
from [Link] import chi2_contingency
observed = [Link]([
[40, 30, 30], # Pune
[35, 35, 30], # Ahmedabad
[45, 25, 30] # Kolkata
])
chi2, p, df, expected = chi2_contingency(observed)
print(chi2, p, df)
Real-Time Example — Clothing Preferences Across Cities
The retailer wants to know if customers in Pune, Ahmedabad, and Kolkata prefer:
• Casual
• Formal
• Sportswear
in similar proportions.
If p > 0.05 → preferences are homogeneous across cities.
If p < 0.05 → preferences differ across cities.
Conclusion
Homogeneity = comparing distributions across populations.
It ensures fairness, consistency, and market segmentation accuracy.
Dis nguis ing Independence vs omogeneit (Cri cal Correctness Skill)
This is the single most confusing area for non-experts.
We cleanly eliminate confusion using a strategic test-selection lens.
Intuition Table (The fastest way to separate them)
Concept Independence Homogeneity
Question Are the two variables related? Are the group distributions identical?
Variables TWO categorical variables ONE categorical variable across multiple populations
E.g. Gender ↔ Purchase Decision City A/B/C purchase distribution comparison
Interpretation Association Consistency across groups
Session notes Page 24
Interpretation Association Consistency across groups
Table view Cross-tab of categories Multiple samples side-by-side
Same function? Yes, chi2_contingency Yes, chi2_contingency
What differs? Hypothesis + meaning Hypothesis + meaning
Formal Distinction
Independence
• Data come from one sample.
• Two variables measured per subject.
Homogeneity
• Data come from multiple samples (populations).
• One variable measured in each sample.
Strategic Rule to Always Get It Right
Ask:
“Are these multiple populations? If yes → homogeneity.”
“Is this simply two variables in one dataset? Then → independence.”
BFSI Examples
Independence
Does loan type depend on customer age?
(One population, two variables per customer.)
Homogeneity
Do three branches show the same distribution of loan types?
(Multiple branches = multiple populations.)
Conclusion
Same math, same function, different meaning.
Never confuse “relationship” with “distribution consistency.”
Iden f ing Correct est from eal orld Scenarios
Intuition
Pattern recognition.
We categorize scenarios into three buckets:
Bucket 1 — Goodness of Fit
“One variable vs expected distribution”
• Uniform expectations
• Ratio-based expectations
• Theoretical model-based expectations
Bucket 2 — Independence
“One population, two categorical variables”
• Customer age × service preference
• Gender × product choice
• Payment mode × satisfaction level
Bucket 3 — Homogeneity
“MULTIPLE populations compared on ONE categorical variable”
• City A/B/C clothing preferences
• OTT engagement distribution across quarters
• Forecast error distribution across models
Examples and Correct Classification
Scenario Correct Test
Airline checks if meal preference equals expected proportion GOF
OTT: Genre preference across India/USA/Brazil Homogeneity
Telecom: Age group vs plan preference Independence
Retail: Seasonal sales expected equal GOF
Fintech: Payment mode preference across 3 cities Homogeneity
Fitness app: Device type vs activity level Independence
Real-Time BFSI Example
Scenario: “Do different bank branches have the same default-risk distribution?”
→ multiple branches → one categorical variable (risk level)
est of omogeneit
Scenario: “Is default risk associated with loan type?”
→ one population → two categorical variables
est of Independence
Conclusion
Correct test selection = exam dominance + real-world analytics competency.
Wrong test = wrong conclusion = wrong decisions.
pot eses for Independence omogeneit
Intuition
Hypotheses define what “no effect” looks like.
Chi-square always tests whether observed differs from expected, but expected differs by case.
Formal Hypotheses
1. Goodness-of-Fit (GOF)
Session notes Page 25
1. Goodness-of-Fit (GOF)
H₀: Observed distribution matches expected distribution
H₁: At least one category differs from expected
Example: Airline meal distribution = expected?
2. Independence
H₀: Variables are independent (no association)
H₁: Variables are dependent (association exists)
Example: Does age influence plan preference?
3. Homogeneity
H₀: All populations share the same distribution
H₁: At least one population differs
Example: Do cities show same clothing preference distribution?
Mathematical Grounding
Each test uses:
But expected (E) differs based on the scenario.
Python Templates
GOF
chisquare(observed, expected)
Independence
chi2_contingency(contingency_matrix)
Homogeneity
(same function)
chi2_contingency(observed_matrix)
Real-Time OTT Example
Expected uniform monthly engagement
H₀: Engagement is evenly distributed across months
H₁: Some months differ significantly
→ GOF.
Conclusion
The structure of hypotheses defines the meaning of the statistical conclusion.
Even if math/test function is identical, meaning changes with formulation.
⭐ MODULE 4 Summary
You now mastered:
• Homogeneity vs Independence
• Formal test-selection logic
• Accurate hypotheses for all chi-square variants
• How to choose the right test from any real-world problem
⭐ MODULE 5 — Interpreting Chi-Square Outputs (The Decision Engine)
Interpre ng t e C i S uare Sta s c (χ²)
Intuition
χ² is the total mismatch between what you saw (observed) and what you expected (under H₀).
Think of χ² as a stress test of your assumption.
• If mismatch is small → χ² small → assumption OK
• If mismatch is large → χ² large → assumption broken
Formal Interpretation
χ2=∑(O−E)2E\chi^2 = \sum \frac{(O - E)^2}{E}χ2=∑E(O−E)2
Properties:
• Always non-negative
• Larger values = more deviation
• Compared against critical value or p-value
Meaning in practice
Small χ²
• Observed ≈ expected
• No major deviation
• H₀ likely true
Large χ²
• Observed far from expected
• Significant structural difference
• H₀ likely false
Python Example
chi2 = 12.48
critical = 12.59
if chi2 < critical:
print("χ² small → fits expectation")
Session notes Page 26
print("χ² small → fits expectation")
else:
print("χ² big → mismatches expectation")
Real BFSI Example
Bank checks if fraud counts across branches follow expected ratios.
χ² = 15.3, df = 3, critical = 7.815
→ χ² > critical
→ fraud distribution differs
→ investigate branch-level fraud patterns
Conclusion
χ² alone doesn't give a final answer but signals whether mismatch is big or small.
Interpre ng p value
Intuition
p-value answers:
“If the null hypothesis were true, how likely is this mismatch?”
Low p-value → mismatch unlikely → reject H₀
High p-value → mismatch plausible → fail to reject H₀
Formal Definition
Interpretation:
• p < α → statistically significant → reject H₀
• p ≥ α → not significant → fail to reject H₀
Common α: 0.05
Meaning
p = 0.80
Results are fully compatible with expectation.
p = 0.10
Not enough evidence; mismatch plausible.
p = 0.03
Mismatch unlikely under H₀ → strong evidence against H₀.
p < 0.0001
Extremely strong evidence → H₀ almost certainly false.
Python Example
chi2, p, df, expected = chi2_contingency(table)
if p < 0.05:
print("Reject H0: Significant association/difference.")
else:
print("Fail to Reject H0: No significant association.")
OTT Example
Genre preference across quarters:
p-value = 0.33 (> 0.05)
→ genre preference is same across quarters
→ stable consumption behavior
Conclusion
p-value is the final decision-maker in inferential statistics.
Interpre ng Cri cal alues
Intuition
Critical value is the threshold above which your mismatch is too large to ignore.
Think of it as:
“If χ² exceeds this, the mismatch is too extreme to be due to chance.”
Formal Definition
Critical value satisfies:
For α = 0.05.
df = (r−1)(c−1)
Example Values
df χ² critical (0.05)
1 3.841
2 5.991
3 7.815
6 12.59
12 21.026
Python Code
Session notes Page 27
from [Link] import chi2
critical = [Link](0.95, df=6)
print(critical)
Airline Example
Meal preferences across 4 types → df = 3
critical = 7.815
If χ² = 12.2 → > 7.815
→ reject H₀
→ preference distribution not equal
Conclusion
Critical value is your cut-off for rejecting/accepting H₀ when using the classical method.
e ect vs. ail to e ect Logic
Intuition
Chi-square cannot prove anything—only disprove stability.
• Reject H₀ → strong evidence of difference/relationship
• Fail to reject → insufficient evidence; doesn’t prove equality
Key idea:
Fail to reject ≠ accept.
It means: “Data doesn’t contradict H₀ strongly enough.”
Formal Logic
Reject H₀ if:
• χ² > critical
• p<α
→ Significant difference → pattern not due to chance.
Fail to reject H₀ if:
• χ² < critical
• p≥α
→ No statistical evidence of difference.
OTT Example
p = 0.33
→ fail to reject H₀
Interpretation:
“User engagement pattern is statistically similar across quarters.”
Conclusion
The chi-square decision is binary:
Mismatch big enough → reject
Mismatch small/plausible → fail to reject
Compu ng Cell ise Contribu on
Intuition
This shows which categories contribute most to the χ² mismatch.
You can detect:
• Cities with most unusual behavior
• Age groups with surprising preferences
• Months with unusual engagement
• Branches with unusual fraud patterns
Formula
For each cell:
Cells with highest contribution explain the deviation.
Why it matters
This is where analytics becomes diagnostic:
• χ² says “there IS a deviation”
• Contributions say “WHO is deviating and HOW MUCH”
Python Example
import numpy as np
from [Link] import chi2_contingency
obs = [Link]([
[30, 10, 10],
[25, 15, 10],
[20, 20, 10]
])
chi2, p, df, expected = chi2_contingency(obs)
contrib = (obs - expected)**2 / expected
print("Contribution matrix:\n", contrib)
print("Largest contributors:", [Link]([Link]())[::-1][:3])
Real Example — Fashion Retailer
Expected for Men–Delhi = 500
Observed = 620
Session notes Page 28
Observed = 620
Contribution:
(620−500)2500=28.8\frac{(620-500)^2}{500} = 28.8500(620−500)2=28.8
Large number → Delhi-Men category is distorting the distribution.
This helps business teams target why patterns differ.
Conclusion
Cell-wise contributions transform chi-square from a “yes/no test” into a powerful diagnostic tool for operational insights.
⭐ MODULE 5 Summary
You now understand:
• How to interpret χ², p-values, and critical values
• How decisions are made
• How to identify the exact categories causing deviations
These skills are essential for analytics, audits, compliance, and business insights.
⭐ MODULE 6 — Strategic Applications, Misuse Prevention, and Decision Logic
usiness pplica ons cross SI etail elecom
Chi-square is a business-critical test whenever decisions involve understanding patterns in categorical data.
Below is a category-wise precision mapping.
Intuition
Use chi-square when your data consists of counts in categories, and you want to check:
• Is it evenly distributed? (GOF)
• Is it associated with another variable? (Independence)
• Is distribution consistent across groups? (Homogeneity)
A. BFSI (Banking, FinTech, Insurance)
Real Problems:
• Default risk across branches
• Fraud type distributions
• Loan type preference by age group
• Payment mode differences across cities
• Insurance claim approval patterns
Example: Loan Default Across Branches
Branches: A, B, C, D
Observed defaults = [50, 40, 30, 20]
Expected = equal (35 each)
from [Link] import chisquare
chisquare([50,40,30,20], [35]*4)
Interpretation:
If p < 0.05 → branch differences not random → audit branches.
B. Retail
Problems:
• Product category preference
• Seasonal demand homogeneity across stores
• Content format preference by demographic
• Customer sentiment distribution vs expectation
Example: Clothing Preference Across Cities
Use χ² Homogeneity → Are distributions same across locations?
C. OTT (Netflix-style)
Problems:
• Genre engagement uniformity across months (GOF)
• Genre preference across countries (Homogeneity)
• Age-group × content-format association (Independence)
Example:
chi2_contingency(
[[180,220,150,200],
[240,210,180,170],
[220,230,160,190]]
)
If p < 0.05 → genre choice varies across countries.
D. Telecom
Problems:
• Age group × plan type
• City × churn reason
• Complaint type distributions
• Service-preference uniformity
Example:
Age × Prepaid/Postpaid → χ² independence
If p < 0.05 → target age-wise marketing.
Conclusion
Chi-square is one of the most indispensable tests in operational analytics, fraud detection, segmentation, recommendation engines, and A/B experimentation for categorical distributions.
Iden f ing rong ests (t test test ) for Categorical Data
Intuition
Session notes Page 29
Intuition
t-test, z-test, ANOVA deal with mean comparisons of numerical (continuous) data.
If your data is counts, these tests are fundamentally invalid.
Example Wrong Usage:
• Using t-test to check if “UPI vs Card preference differs”
• Using ANOVA to compare customer sentiment categories
Formal Diagnostic Tool
Use this rule:
If your variable is:
• Numerical, continuous → t-test, z-test, ANOVA
• Categorical, counts → χ² tests
Checklist for Wrong Test Detection
Wrong:
• Running t-test on 3-category meal preference → meals aren’t continuous
• Using ANOVA on branches’ default frequencies → dependent counts
Right:
• χ² GOF / independence / homogeneity
Python Example — Wrong Test Warning
# WRONG: t-test on categorical counts
from [Link] import ttest_ind
ttest_ind([40,30,30], [35,35,30]) # meaningless
The output has no statistical meaning.
Retail Example
Customer preference for Casual/Formal/Sportswear is NOT numerical.
→ ANOVA is invalid
→ χ² homogeneity is correct
Conclusion
Choosing the wrong test produces invalid insights → wrong business decisions.
Chi-square is the correct tool for categorical comparisons.
ul Categor ul roup Comparison Logic
Intuition
When multiple categories AND multiple groups appear together, we must map correctly:
Cases:
• 1 variable, many categories → GOF
• 2 variables of any sizes (3×4, 2×5, 6×3…) → Independence
• One variable × multiple populations → Homogeneity
Decision Table
Data Structure Correct Test
1 categorical variable vs expectation GOF
2 categorical variables from same population Independence
1 categorical variable from multiple populations Homogeneity
Python Examples
GOF (1×k)
chisquare([240,210,90,60], [150]*4)
Independence (r×c)
chi2_contingency([[30,10,10],[25,15,10],[20,20,10]])
Homogeneity (same function)
chi2_contingency([[180,220,150,200],
[240,210,180,170],
[220,230,160,190]])
OTT Example
To compare 4 genres across 3 quarters, use χ² homogeneity.
To check if UserGender affects FavoriteGenre, use χ² independence.
Conclusion
Correct mapping avoids statistical overkill and misinterpretation.
a o ased xpected re uenc Calcula ons
Intuition
Some expectations are not uniform—companies often have business ratios.
Example:
• Customer feedback expected ratio: 3:2:1
• Sentiment expected ratio: 50% positive, 30% neutral, 20% negative
Expected frequencies = proportional allocation of total.
Formal Definition
Session notes Page 30
Formal Definition
Example
Observed = [180, 120, 100]
Ratios = 3:2:1
Total = 400
Expected:
• Pos = 400 × 3/6 = 200
• Neu = 400 × 2/6 = 133.33
• Neg = 400 × 1/6 = 66.66
Python
import numpy as np
ratios = [Link]([3,2,1])
observed = [Link]([180,120,100])
expected = [Link]() * ratios / [Link]()
print(expected)
Retail Example
A brand expects purchase distribution of:
• Men 40%
• Women 40%
• Kids 20%
If observed differs significantly, marketing allocation must be adjusted.
Conclusion
Ratio-based expectations are a powerful alignment tool for business benchmarks.
niform Distribu on ssump ons
Intuition
Uniform expectation = all categories equally likely.
Used when:
• Company expects even distribution
• No reason to believe categories differ
• A fairness policy exists
• Seasonal effects shouldn’t exist
Formal Definition
For k categories:
Ei=NkE_i = \frac{N}{k}Ei=kN
Use Cases
• Airline assumes equal meal demand
• OTT expects uniform monthly engagement
• Retailer assumes equal preference for sizes
• Bank assumes equal fraud distribution
Python Example
import numpy as np
obs = [Link]([240,210,90,60])
exp = [Link]([Link]()/len(obs), len(obs))
Conclusion
Uniform expectations are the default unless domain knowledge dictates otherwise.
ow to Conclude wit Sta s cal Signi cance
Intuition
Statistical significance is the final verdict:
“Is the deviation from expectation more than random noise?”
Steps
Compute χ²
Compute df
Compute p value (or compare χ² with cri cal)
If p < α → reject H₀
Use cell contribu ons to iden fy where mismatch occurs
Translate into business ac on
Python Template
chi2, p, df, expected = chi2_contingency(observed)
if p < 0.05:
print("Reject H0: Significant difference/association.")
else:
print("Fail to reject H0: No significant evidence.")
OTT Example
Testing if monthly engagement is uniform:
Session notes Page 31
Testing if monthly engagement is uniform:
• χ² = 1484.57
• critical = 12.59
• p≈0
→ REJECT H₀
→ months differ → use seasonal push marketing
Conclusion
Statistical significance translates mismatches into actionable insights:
reallocation, segmentation, fraud detection, churn prevention, demand forecasting.
⭐ MODULE 6 Summary
You now master:
• Strategic business applications
• How NOT to misuse statistical tests
• Multi-group logic
• Ratio-based & uniform expectations
• Real decision-making with statistical significance
⭐ MODULE 7 — Integrated Case Analysis, Thought Frameworks, and Mastery
This final module ties everything together so you can diagnose, reason, select tests, and defend results like a top 0.01% statistician.
Topics:
1. Holistic test-selection reasoning
2. Multi-layer question dissection (exam mastery)
3. Forensic error-checking (spot wrong inferences)
4. Stress-testing assumptions
5. Reverse engineering expected frequencies
6. Multi-lens business case modeling
7. Meta-conclusion frameworks (how to justify decisions)
olis c est Selec on easoning ( e Step Classi er)
Intuition
Every chi-square problem collapses into one of three types:
• GOF
• Independence
• Homogeneity
Instead of memorizing, you use a deterministic decision tree:
FORMAL 4-STEP DECISION TREE
STEP 1 — Count the variables.
• One variable → GOF
• Two variables → Independence or Homogeneity
STEP 2 — Ask:
“Do I ave population or L IPL populations?”
• One population → Independence
• Multiple populations → Homogeneity
STEP 3 — Ask:
“Is t ere an expected t eoretical distribution?”
• Yes → GOF
• No → Independence or Homogeneity
STEP 4 — Construct hypothesis based on test type
• GOF: Observed = expected?
• Independence: variables unrelated?
• Homogeneity: groups identical?
Deep Mathematical Understanding
This decision tree is equivalent to analyzing the structure of the contingency matrix:
Shape clues
• 1×k → GOF
• r×c, r> and categorical variables → Independence
• r samples each with c categories → Homogeneity
Python: Automated Classifier Implementation
def classify_test(shape, expectations=False, populations=1):
rows, cols = shape
if expectations and rows == 1:
return "Goodness-of-Fit"
if populations > 1:
return "Chi-Square Test of Homogeneity"
if rows > 1 and cols > 1:
return "Chi-Square Test of Independence"
return "Insufficient Data"
print(classify_test((3,4), expectations=False, populations=3))
Output:
“Chi-Square Test of Homogeneity”
Real Example — FinTech PSP Data
Payment modes across three cities (UPI, Card, NetBanking):
• 3 populations (cities)
• 3 categories (payment modes)
• No theoretical expectation
✔ Homogeneity
Session notes Page 32
✔ Homogeneity
Conclusion
You no longer memorize “tests”; you classify problems algorithmically.
This creates immunity to exam trick questions.
ul La er ues on Dissec on ( xam aster lgorit m)
Exam questions are usually camouflage puzzles.
I’ll give you the Surgical 7-Step Dissection Method.
Step-by-Step Intuition
STEP 1: Identify data type
Categorical? Count? Ratio? Continuous?
STEP 2: Identify number of variables
One variable → GOF
Two variables → Independence/Homogeneity
STEP 3: Identify populations
Single dataset? Multiple groups?
STEP 4: Determine expectation
Uniform? Ratio-based? None?
STEP 5: Extract distribution shape
Rows × Columns → df
STEP 6: Interpret p-value / critical
STEP 7: Business conclusion
Translate stats into decision.
Formal Framework Example
Problem:
"A clothing retailer wants to know if customer preference for 5 categories is uniform across 3 cities."
Step mapping:
1. categorical → chi-square
2. two dimensions
3. 3 cities → multiple populations
4. no theoretical expectation
5. 3×5 → df = (3-1)(5-1) = 8
6. compare p
7. conclude if preferences differ across geography
✔ Homogeneity test.
Python Simulation for Practice
import numpy as np
from [Link] import chi2_contingency
# simulate 3 cities × 5 categories
obs = [Link](50,200,(3,5))
chi2,p,df,exp = chi2_contingency(obs)
print("Observed:\n",obs)
print("Expected:\n",exp)
print("Decision:", "Reject H0" if p<0.05 else "Fail to Reject H0")
Conclusion
This 7-step method is exam-proof and industry-proof.
It always arrives at the correct test and conclusion.
orensic rror C ecking (Spot istakes Like a Pro)
Students usually commit these errors. Your job is to forensically detect and correct them.
❌ ERROR 1 — Using t-test/ANOVA on categorical data
Fix: Only use chi-square for frequency tables.
❌ ERROR 2 — Expected values not summing to total
Fix: Check:
∑Ei=∑Oi\sum E_i = \sum O_i∑Ei=∑Oi
❌ ERROR 3 — Expected < 5 (invalid chi-square)
Fix: Merge categories.
❌ ERROR 4 — Wrong hypothesis
Fix: Rewrite H₀/H₁ based on test type.
❌ ERROR 5 — Misreading fail-to-reject as acceptance
Fix: FTR ≠ acceptance. It means insufficient evidence.
❌ ERROR 6 — Assuming independence = homogeneity
Fix: Independence = within one population
Homogeneity = across populations
Conclusion
Error detection is your intellectual shield against sloppy analytics.
Stress es ng ssump ons
Before concluding chi-square results, ask:
1. Are observations independent?
Repeated customer → violation
2. Are expected frequencies ≥ 5?
Session notes Page 33
2. Are expected frequencies ≥ 5?
If not → Fisher Exact or merge
3. Is sample size enough?
N < 30 → unreliable
4. Is sampling random?
If not → bias
5. Are categories mutually exclusive?
E.g., customer selecting multiple genres → violates assumption
Python: Assumption Checker
def check_assumptions(expected):
if (expected < 5).any():
print("Expected < 5 — chi-square unreliable")
else:
print("Assumptions satisfied")
Conclusion
Without assumption validation, chi-square conclusions collapse.
everse ngineering xpected re uencies
Often exams give:
• Observed
• Expected for one cell
• Grand total
You must find expected for other cells.
Formal Formula
Eij=(Row Totali)(Column Totalj)Grand TotalE_{ij} = \frac{(\text{Row Total}_i)(\text{Column Total}_j)}{\text{Grand Total}}Eij=Grand Total(Row Totali)(Column Totalj)
Example
Given:
Row total (January) = 11,232
Column total (Action) = 38,260
Grand total = 117,017
Expected:
E=11232×38260117017=3669.42E = \frac{11232 \times 38260}{117017} = 3669.42E=11701711232×38260=3669.42
Conclusion
Reverse engineering is essential for exam questions where expected frequencies aren't directly given.
ul Lens usiness Case odeling
To operate at elite level, interpret results through five business lenses:
Lens 1 — Operational
High χ² for a category → bottleneck or anomaly.
Example: Fraud spike in one branch.
Lens 2 — Marketing
Homogeneity failure → city-specific targeting needed.
Example: Apparel preferences differ by city.
Lens 3 — Product Analytics
Independence failure → feature usage differs by segment.
Example: Age drives content format choice.
Lens 4 — Finance
GOF failure → revenue assumptions wrong.
Example: Monthly demand not uniform.
Lens 5 — Strategy
Chi-square insights shape segmentation, resource allocation, forecasting.
Conclusion
Statistical results → business action → revenue impact.
eta Conclusion ramework
Whenever you finish a chi-square test, deliver conclusions using this 5-sentence format:
SENTENCE BLUEPRINT
State t e test used
→ “A chi-square test of independence was conducted…”
State pot esis
→ “H₀ assumed age and plan type were independent.”
State sta s cal result
→ “p = 0.013 < 0.05 → reject H₀.”
State interpreta on
→ “Age and plan preference are statistically associated.”
State business impact
→ “Telecom should design age-specific plan offerings.”
Session notes Page 34
Conclusion
This blueprint turns raw numbers into a sharp executive summary.
⭐ MODULE 7 SUMMARY
You mastered:
• Universal test-selection logic
• Exam-proof question dissection
• High-level error detection
• Assumption validation
• Reverse expected-value engineering
• Business interpretation lenses
• Executive conclusion framework
Session notes Page 35
Day-5
1. Intuition of the Model Architecture
Core Idea
Linear regression attempts to explain and predict a variable (say, price) using one or more input features (say, size, age, distance).
It fits the best possible straight line (or hyperplane) through the data.
Geometric Intuition
• In simple linear regression:
We fit a line
•
• that minimizes the vertical distances (errors) between actual points and the line.
• In multiple linear regression:
The line becomes a plane or hyperplane in higher dimensions.
2. Formal Definition of Linear Regression
Linear regression is a statistical method that models the relationship between a dependent variable yyy and one or more independent variables x1,x2,…,xp by fitting a linear function to observed data.
The model is defined as:
Where:
• β0 = intercept
• β1,β2,…,βp = coefficients
• ε = random error term with mean 0 and constant variance
• Relationship is linear in parameters β
The goal is to estimate β such that predictions
are as close as possible to actual values y.
at “best” means?
The best line has coefficients that minimize the Sum of Squared Errors (SSE):
This is called Ordinary Least Squares (OLS).
Aspect OLS (Normal Equation) SVD Regression
Numerical stability Low Extremely high
Handles multicollinearity No Yes
Works when (p > n) No Yes
Sensitivity to noise High Low
Computational cost Moderate Higher but robust
Used in sklearn Only optionally Default everywhere
3. Assumptions of Linear Regression
To trust the model, these assumptions should hold:
1. Linearity
Relationship between predictors and target is linear in parameters.
2. Independence
Observations are independent.
3. Homoscedasticity
Residuals have constant variance—no funnel shape.
4. Normality of Residuals
Residuals should be approximately normally distributed (important for inference).
5. No Multicollinearity
Predictors should not be highly correlated with each other.
Variance Inflation Factor (VIF) helps identify this.
6. No autocorrelation (for time series)
Residuals should not be correlated with themselves (Durbin–Watson test).
4. Code Using Scikit-Learn
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from [Link] import mean_squared_error, r2_score
# Load dataset
df = pd.read_csv("[Link]") # Replace with your dataset
# Select features and target
X = df[['feature1', 'feature2']]
y = df['target']
# Train-test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Model
model = LinearRegression()
[Link](X_train, y_train)
# Predictions
y_pred = [Link](X_test)
Session notes Page 36
y_pred = [Link](X_test)
# Performance
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)
print("Coefficients:", model.coef_)
print("Intercept:", model.intercept_)
print("MSE:", mse)
print("R²:", r2)
5. Code From Scratch (Using OLS Closed Form)
import numpy as np
# Example data
X = [Link]([[1, 2], [2, 3], [3, 4]]) # features
y = [Link]([4, 5, 6]) # target
# Add intercept term
X_b = np.c_[[Link](([Link][0], 1)), X]
# OLS solution
beta = [Link](X_b.[Link](X_b)).dot(X_b.T).dot(y)
print("Intercept:", beta[0])
print("Coefficients:", beta[1:])
6. Performance Metrics
1. Mean Absolute Error (MAE)
2. Mean Squared Error (MSE)
3. Root Mean Squared Error (RMSE)
4. R-squared (R², Coefficient of Determination)
How much variance in target is explained by model.
5. Adjusted R²
Penalizes unnecessary predictors.
7. Visualization of Results
1. Scatter Plot with Regression Line (Simple Regression)
import [Link] as plt
[Link](X_test, y_test, label="Actual")
[Link](X_test, y_pred, color='red', label="Predicted")
[Link]("X")
[Link]("y")
[Link]("Regression Line")
[Link]()
[Link]()
2. Residual Plot
residuals = y_test - y_pred
[Link](y_pred, residuals)
[Link](0, color='red')
[Link]("Residual Plot")
[Link]("Predicted")
[Link]("Residuals")
[Link]()
3. Histogram of Residuals
[Link](residuals, bins=20)
[Link]("Residual Distribution")
[Link]()
8. Conclusion
Linear regression is the foundation of predictive modeling.
It is mathematically elegant, computationally light, and serves as a baseline for advanced models.
What students must take away:
• Understand the intuition: fit a line that best explains the variability.
• Know the assumptions: linear, independent, constant variance, normal errors.
• Implement using scikit-learn or write OLS manually.
• Evaluate with MAE, MSE, RMSE, R², and residual analysis.
• Visualize the model to validate assumptions.
It is not just a tool—it is a discipline for diagnosing data, understanding relationships, and building interpretable models.
Session notes Page 37
Classification
1. Intuition of the Model Architecture + Formal
Definition
Intuition
• You’re predicting probabilities of belonging to class 1 vs class 0.
• Linear regression gives unbounded outputs (−∞ to +∞) → impossible to interpret as
probabilities.
• Logistic regression transforms the linear combination of features into a probability curve (S-
curve) using the sigmoid function, ensuring values stay in [0,1].
• Decision boundary is determined by:
• Model learns parameters w,b by maximizing the likelihood of observing true labels.
• Training uses Gradient Descent on the Binary Cross-Entropy (Log Loss) function.
1. Confusion Matrix
TP, TN, FP, FN.
2. Accuracy
3. Precision
Useful when false positives are costly.
4. Recall (Sensitivity)
Useful when false negatives are costly (e.g., cancer detection).
Session notes Page 38
6. ROC Curve
Plots TPR vs FPR at different thresholds.
7. AUC
Probability model ranks a positive above a negative.
8. Log Loss
Directly matches logistic regression objective.
9. Classification Report
Precision, Recall, F1 per class.
6. Conclusion (Strategic Takeaways)
• Logistic Regression is a probabilistic, interpretable, convex model.
• Acts as a linear classifier but outputs continuous probabilities → ideal for risk scoring.
• Works best when:
○ Linear decision boundary is reasonable.
○ Dataset is not extremely high-dimensional.
○ You need model explainability (weights are interpretable).
• Weaknesses:
○ Struggles with non-linear relationships.
○ Sensitive to multicollinearity.
○ Not ideal for large feature interactions → tree models outperform in such settings.
• Still highly valuable in:
○ BFSI (credit scoring, fraud risk)
○ Healthcare (disease prediction)
○ Marketing (churn, conversion probability)
○ Operations (quality control)
Session notes Page 39
KNN
KNN makes no assumptions about data distribution.
It memorizes the training dataset and performs lazy learning:
• When you give a new point x*, KNN finds the k closest points in the training set using a
distance metric (Euclidean, Manhattan, Minkowski, cosine).
• It then votes (classification) or averages (regression).
Think of it as:
“Show me the nearest neighbors; I trust the local neighborhood to infer the answer.”
This makes KNN sensitive to:
• Local density
• Noise
• Feature scaling
There is no explicit parametric model. The architecture is:
Training Phase
• Store matrix X_train ∈ ℝⁿˣᵈ
• Store labels y_train ∈ ℝⁿ
Prediction Phase for x*
1. Compute distance:
• p = 2 → Euclidean
• p = 1 → Manhattan
• p → Minkowski
• Sort distances:
Aggregation:
• Classification: majority vote
Regression: mean
K selection (Bias–Variance sweep)
Plot error vs K:
• Small K → high variance (overfits)
• Large K → high bias (underfits)
Conclusion
Strengths
• Non-parametric, no training time.
• Very strong for well-separated classes.
• Useful for low-dimensional structured datasets.
• Simplest baseline model for anomaly detection or tabular classification.
Session notes Page 40
• Simplest baseline model for anomaly detection or tabular classification.
Weaknesses
• Expensive at inference (O(n·d)).
• Breaks without scaling.
• Hurt by irrelevant/noisy features.
• Can’t handle high dimensionality (curse of dimensionality).
• Sensitive to class imbalance and distance metric choice.
Strategic Takeaway
KNN is a high-bias baseline for fast prototyping, not a production model for large or high-
dimensional datasets.
Its main value today (2025 context) is:
• Benchmark against more complex models
• Sanity-check the separability of data
• Quick interpretability for tabular tasks
If KNN performs well, your dataset likely has strong local clusters and favorable geometric structure.
Metric Weighting Meaning
Macro F1 Equal weight to every class Tests per-class quality
Micro F1 Equal weight to every sample Tests overall correctness
Session notes Page 41
Session notes Page 42
K-means
1. Intuition of Model Architecture & Formal Definition
Intuition
K-Means is a prototype-based, iterative, unsupervised clustering algorithm that finds K dense
regions in the feature space.
The algorithm tries to minimize within-cluster variance, i.e., points in the same cluster should be as
similar as possible.
Mechanics:
1. Randomly place K centroids.
2. Assign each point → nearest centroid (Voronoi partition).
3. Recompute centroids → mean of assigned points.
4. Repeat until centroids stabilize (convergence).
It is basically:
• A coordinate-descent algorithm on cluster assignments.
• An Expectation-Maximization (EM)–like procedure but with hard assignments.
Session notes Page 43
Method Metric Goal
Elbow WCSS Find elbow point
Silhouette Silhouette score Maximize
Session notes Page 44
Evaluation metrics
1. MAE (Mean Absolute Error)
What it measures: Average magnitude of errors — linear penalty.
Interpretation:
• MAE = 5 means: on average, predictions are off by 5 units.
• Robust to outliers; stable metric for messy business data (BFSI, retail, operations).
Pros: Interpretable, less sensitive to extreme values.
Cons: Doesn’t penalize large errors strongly.
2. MSE (Mean Squared Error)
What it measures: Average of squared errors — quadratic penalty.
Interpretation:
• MSE is high = model is making some large mistakes.
• Used when you want the model to fear big deviations.
Pros: Punishes large errors → useful in high-risk domains (fraud, credit, forecasting).
Cons: Harder to interpret (squared units), extremely sensitive to outliers.
3. RMSE (Root Mean Squared Error)
What it measures: Square root of MSE → brings unit back to original scale.
Interpretation:
• If RMSE = 12, predictions deviate by ~12 units typically.
Pros: Balanced metric; heavy penalty on big errors but interpretable.
Cons: Outliers can dominate.
4. R² (Coefficient of Determination)
What it measures: % of variance explained by model.
Interpretation:
• R² = 0.80 → model explains 80% of the variation in target.
• R² = 0 → model no better than mean.
• R² < 0 → model worse than predicting average.
Pros: Fast sanity check on model strength.
Cons: Can be misleading under multicollinearity or non-linear patterns.
5. Adjusted R²
What it measures: Penalizes unnecessary features.
Interpretation:
• If R² increases but Adjusted R² decreases → new feature is useless/noise.
Pros: Corrects R² inflation in MLR.
Cons: Still doesn’t guarantee causality or relevance.
CLASSIFICATION METRICS — Interpretation
Confusion Matrix Terms
Session notes Page 45
Confusion Matrix Terms
• TP: Correctly predicted positives
• TN: Correctly predicted negatives
• FP: Model falsely predicts positive (Type I error)
• FN: Model falsely predicts negative (Type II error)
Interpret errors differently based on business:
• Healthcare: FN is deadly (missing cancer).
• Fraud detection: FP is tolerable; FN is costly.
• Credit scoring: Both FP and FN have financial consequences.
1. Accuracy
What it measures: % of correct predictions.
Interpretation:
• Works only when classes are balanced.
• If dataset = 95% negative, predicting “negative” always gives 95% accuracy (useless).
2. Precision
What it measures: Of predicted positives, how many were correct?
Interpretation:
• Precision = 0.90 → 90% of positive predictions were correct.
Useful when FP is costly:
• Spam detection
• Credit approval
• Medical treatment recommendation
3. Recall (Sensitivity/TPR)
What it measures: Of true positives, how many did the model catch?
Interpretation:
• Recall = 0.95 → model correctly catches 95% of actual positives.
Useful when FN is costly:
• Cancer detection
• Fraud detection
• Safety systems
4. F1 Score
What it measures: Harmonic mean of Precision and Recall.
Interpretation:
• F1 = 0.85 → strong balance between precision & recall.
• Especially useful for imbalanced datasets.
Macro F1: equally weights classes (good for imbalance).
Micro F1: weights by frequency (good when class imbalance is mild).
5. ROC–AUC (Area Under ROC Curve)
What it measures: Ability to distinguish classes at different thresholds.
Interpretation:
• AUC = 0.5 → no discrimination (random).
• AUC = 0.7–0.8 → acceptable.
• AUC = 0.8–0.9 → strong.
• AUC > 0.9 → excellent (or suspicious/overfit).
Useful for:
• Credit scoring (industry standard)
• Risk models
• Fraud scoring
REGRESSION → When to Use What
Session notes Page 46
REGRESSION → When to Use What
Metric Use Case
MAE interpretability, noisy data
RMSE high-risk errors matter
R² / Adjusted R² feature importance sanity check
CLASSIFICATION → When to Use What
Metric Best For Avoid When
Accuracy balanced data imbalanced data
Precision FP expensive FN expensive
Recall FN expensive FP expensive
F1 need balance perfectly symmetric cost
ROC–AUC ranking ability extreme imbalance
Session notes Page 47
Revision
p-value is the probabilistic stress test you apply to your null hypothesis.
Stripped to its essence:
The p-value is the probability of observing data at least as extreme as your sample,
assuming the null hypothesis is true.
This is not the probability that the null is true. It is the probability of your evidence under the null’s
worldview.
Breakdown with surgical precision
1. What it measures
If the null hypothesis says:
“Nothing interesting is happening; the effect is zero,”
then the p-value asks:
“How likely is this sample to appear just by random chance if the null were correct?”
• High p-value (≥ α) → The data is plausible under the null.
• Low p-value (< α) → The data is too extreme under the null → grounds to reject.
2. Think in distributions
Every test statistic (Z, t, χ², F) belongs to a known distribution under the null.
• You compute your test statistic from the sample
• You drop it onto the null distribution
• The p-value measures the tail-area beyond your observed statistic
That tail area = probability of equal or more extreme outcomes under the null.
4. Interpretations (precise and ruthless)
Correct interpretation
✔ “If the null were true, the probability of seeing a result this extreme or more extreme is p.”
Wrong interpretations (common traps)
✘ p-value is not “probability the null is true.”
✘ p-value is not “probability you made a mistake.”
✘ p-value is not “importance of the result.”
✘ p-value is not “effect size.”
5. Decision rule
If p < α (usually 0.05):
Session notes Page 48
If p < α (usually 0.05):
• Evidence is inconsistent with the null → reject H0
• If p ≥ α:
• Evidence is insufficient → fail to reject H0
Notice: Failing to reject is not the same as accepting the null.
6. Quick numerical intuition
Suppose μ = 50 under H₀.
You observe a sample mean of 60 with tight variance → Z = 2.8.
Tail area for Z = 2.8 ≈ 0.0026.
Interpretation:
“If the true mean were 50, only 0.26% of samples would produce a mean this extreme.”
→ Reject H₀.
Session notes Page 49
Revision_0
CENTRAL LIMIT THEOREM (CLT)
When you repeatedly take samples from any population and compute their means, the distribution
of those means tends toward normal, no matter the population’s original shape—provided sample
size is reasonably large (n ≥ 30).
Why it works: each sample mean is a summation of random variables. Summations “average out”
the irregularities in the parent distribution because of the law of large numbers + variance shrinking
by 1/n.
Application (Practical Use Cases)
• Confidence intervals for unknown mean
• Z-tests & t-tests
• Bootstrapping
• Risk estimation (BFSI): portfolio mean loss spreads
• A/B testing: difference in conversion rate means
• Operational analytics: delivery-time averages, production times, etc.
CLT breaks down slightly under:
• n < 30
• Dependent samples
Scenario Does CLT hold? Why
Heavy-tailed (Pareto α < 2) Weak variance → ∞ breaks assumptions
Bimodal population Yes means average the two modes
n = 10 Approx only distribution still skewed
Correlated samples (time-series) No i.i.d broken
Non-identical distributions Partial Lindeberg–Feller variants required
1) WHAT is a Z-Test?
A parametric hypothesis test used when:
• The sampling distribution of the mean is approximately normal
• The population variance/standard deviation is known or sample size is large (n ≥ 30)
It checks whether sample means differ significantly from a known value or from each other.
Mathematically, the Z-statistic is
2) WHY do we use a Z-Test?
Because in many real-world problems:
• You want to check if your sample behaves like the population
• Or compare two populations
• And you often have large samples or known variance → Z-tests become valid and powerful
Scenario Test Meaning
Bank wants to check if new onboarding process reduced One-sample Compare sample mean to
average waiting time Z old mean
Claims team validates if average claim amount increased Two-sample Compare means of before
after policy change Z vs after
Hospital tests if a new drug reduces recovery time Two-sample Compare control vs
Z treatment
Session notes Page 50
E-commerce checks if average cart value differs for Two-sample Two independent user
mobile vs desktop Z groups
Marketing tests if new ad campaign's average clicks One-sample Compare sample mean to
differ from target Z target
Z-tests are used because:
• They work well with large data (CLT)
• They give fast inference
• They are easy for executives/stakeholders to interpret
3) HOW does a One-Sample Z-Test work?
Purpose
To check if your sample mean differs from a known population mean.
Step-by-step
Step 1: Define hypotheses
• H₀: μ = μ₀
• H₁: μ ≠ μ₀ (or >, < depending on question)
Step 2: Compute Z statistic
Where:
• Xˉ= sample mean
• μ0 = claimed population mean
• σ= population standard deviation
• n = sample size
Step 3: Compute p-value or compare with Z-critical
Typical Z-critical:
• 1.96 (for α = 0.05, two-tailed)
• 1.645 (for α = 0.05, one-tailed)
Step 4: Decision
Reject H₀ if p < α or |Z| > Z-critical.
1) WHAT is a t-test?
A parametric hypothesis test used when:
• The population variance is unknown
• Sample size is small (n < 30) or moderate
• Data is approximately normal
It evaluates whether sample means differ significantly from a known value or from each other,
using the t-distribution instead of the Z-distribution.
General structure
But the denominator uses sample standard deviation rather than population SD.
2) WHY do we use a t-test?
Because in the real world:
• You rarely know the population standard deviation
• Sample sizes for experiments, pilots, medical trials, A/B tests are often small
• The t-distribution accounts for extra uncertainty from using sample variance
This makes the t-test the default workhorse for:
• A/B testing, experimental design
Session notes Page 51
• A/B testing, experimental design
• Clinical trials
• Operational performance comparisons
• Product, policy, or process change validation
• Training vs. control group comparisons
• Quality control
• Small-sample analytics (common in BFSI risk, healthcare research, surveys)
The t-distribution has heavier tails, which means it is more conservative for small sample sizes.
3) HOW does a One-Sample t-Test work?
Purpose
Checks whether a sample mean differs from a known reference mean.
Step-by-Step
1) Hypotheses
• H₀: μ = μ₀
• H₁: μ ≠ μ₀ (or >, <)
2) Compute the t-statistic
1) WHAT is Chi-Square Goodness-of-Fit?
A non-parametric statistical test that checks:
Does my observed categorical distribution match a claimed/theoretical/expected
distribution?
In formal terms:
You compare bserved Fre uencies ( ᵢ) vs. E pected Fre uencies (Eᵢ) across k categories using:
Large deviations ⇒ large χ² ⇒ low p-value ⇒ distribution does not fit the claim.
2) WHY do we use it?
Because categorical data rarely matches theory perfectly; we need a statistical mechanism to test:
Session notes Page 52
Because categorical data rarely matches theory perfectly; we need a statistical mechanism to test:
• Are customer complaints distributed evenly?
• Is a die fair?
• Do purchase frequencies follow a known historical ratio?
• Does website traffic distribution match target market segments?
• Do ad-click categories follow expected proportions?
Domain Example
BFSI Fraud type distribution vs. historical fraud patterns
Retail Product return reasons vs. expected ratios
OTT Genre-watch distribution vs. predicted model
Healthcare Distribution of symptoms vs. medical reference distribution
HR Analytics Hiring distribution vs. diversity targets
In short:
It detects distributional anomalies → extremely useful for fraud detection, risk modeling, and audit
analytics.
3) HOW does the Chi-Square GOF test work? (Step-
wise)
Step 1: Define Hypotheses
• H₀: Observed distribution fits the expected distribution.
• H₁: Observed distribution does NOT fit the expected distribution.
Step 2: Collect Observed Frequencies (O)
Example — survey of favorite colors (n = 200):
• Red: 70
• Blue: 50
• Green: 40
• Yellow: 40
Step 3: Define Expected Frequencies (E)
These come from a claim, theory, policy, or historical data.
Examples:
• Equal probability → 50, 50, 50, 50
• Known market share ratio
• Theoretical Mendelian genetics ratio (3:1)
Expected frequencies must sum to total sample size.
Step Compute χ² statistic
Step 5: Degrees of freedom
df=k−1
Where k = number of categories.
Step 6: Compute p-value
Use:
• [Link]()
• or χ² distribution table
Step 7: Decision
If p < α (commonly 0.05):
Reject H₀ → The observed distribution does not match the expected distribution.
Session notes Page 53
Reject H₀ → The observed distribution does not match the expected distribution.
You roll a die 60 times.
Observed: [8, 10, 11, 9, 12, 10]
Expected for each side: 10
Compute:
If χ² is small → die behaves as expected.
If χ² is large → die may be biased.
WHAT: A test comparing observed vs. expected categorical frequencies.
WHY: To check if a distribution matches theory/claim; critical for anomaly detection and validation.
HOW: Compute χ² = Σ((O−E)²/E), compare with χ² distribution, reject H₀ if p < α.
Session notes Page 54