Articles → MACHINE LEARNING → Chi-Square In Machine Learning

Chi-Square In Machine Learning






Purpose





Steps




  1. Define Hypothesis.
  2. Build a Contingency table.
  3. Find the expected values.
  4. Calculate the Chi-Square Values.
  5. Accept or Reject the Null Hypothesis.

Sample Data


GenderTeaCoffeeBoth
Male10155
Female5105



Define Hypothesis


  1. H₀: Gender and drink preference are independent (no association).
  2. H₁: Gender and drink preference are not independent (there is an association).

Build A Contingency Table




GenderOnly TeaOnly CoffeeBothRow Total
Male510520
Female05510
Column Total5151030


Grand Total = 30



Find The Expected Values




Picture showing




GenderOnly TeaOnly CoffeeBoth
Male20*5/3020*15/3020*10/30
Female10*5/3010*15/3010*10/30




GenderOnly TeaOnly CoffeeBoth
Male3.33106.67
Female1.6753.33



Calculate The Chi-Square Values




Picture showing


GenderCategoryOEO−E(O−E)²(O−E)²/E
MaleOnly Tea53.331.672.790.837
MaleOnly Coffee1010000
MaleBoth56.67-1.672.790.418
FemaleOnly Tea01.67-1.672.791.67
FemaleOnly Coffee55000
FemaleBoth53.331.672.790.837


χ2=0.837+0+0.418+1.67+0+0.837=3.762



Degree Of Freedom




Picture showing




df=(2−1) * (3−1)=2



X2 Critical Value




X2 critical value=5.991 (use any online calculator)



Conclusion


χ² statisticDecision
χ² < χ²_criticalAccept H₀
χ² ≥ χ²_criticalReject H₀



Posted By  -  Karan Gupta
 
Posted On  -  Thursday, November 20, 2025

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250