Articles → MACHINE LEARNING → Chi-Square In Machine Learning
Chi-Square In Machine Learning
Purpose
Steps
- Define Hypothesis.
- Build a Contingency table.
- Find the expected values.
- Calculate the Chi-Square Values.
- Accept or Reject the Null Hypothesis.
Sample Data
| Gender | Tea | Coffee | Both |
|---|
| Male | 10 | 15 | 5 |
| Female | 5 | 10 | 5 |
Define Hypothesis
- H₀: Gender and drink preference are independent (no association).
- H₁: Gender and drink preference are not independent (there is an association).
Build A Contingency Table
| Gender | Only Tea | Only Coffee | Both | Row Total |
|---|
| Male | 5 | 10 | 5 | 20 |
| Female | 0 | 5 | 5 | 10 |
| Column Total | 5 | 15 | 10 | 30 |
Find The Expected Values
| Gender | Only Tea | Only Coffee | Both |
|---|
| Male | 20*5/30 | 20*15/30 | 20*10/30 |
| Female | 10*5/30 | 10*15/30 | 10*10/30 |
| Gender | Only Tea | Only Coffee | Both |
|---|
| Male | 3.33 | 10 | 6.67 |
| Female | 1.67 | 5 | 3.33 |
Calculate The Chi-Square Values
| Gender | Category | O | E | O−E | (O−E)² | (O−E)²/E |
|---|
| Male | Only Tea | 5 | 3.33 | 1.67 | 2.79 | 0.837 |
| Male | Only Coffee | 10 | 10 | 0 | 0 | 0 |
| Male | Both | 5 | 6.67 | -1.67 | 2.79 | 0.418 |
| Female | Only Tea | 0 | 1.67 | -1.67 | 2.79 | 1.67 |
| Female | Only Coffee | 5 | 5 | 0 | 0 | 0 |
| Female | Both | 5 | 3.33 | 1.67 | 2.79 | 0.837 |
χ2=0.837+0+0.418+1.67+0+0.837=3.762
Degree Of Freedom
X2 Critical Value
X2 critical value=5.991 (use any online calculator)
Conclusion
| χ² statistic | Decision |
|---|
| χ² < χ²_critical | Accept H₀ |
| χ² ≥ χ²_critical | Reject H₀ |
| Posted By - | Karan Gupta |
| |
| Posted On - | Thursday, November 20, 2025 |