Created
October 13, 2021 19:38
-
-
Save manisnesan/0432f961aa6cbeb13e5363df22fbeca7 to your computer and use it in GitHub Desktop.
Chi Squared Test to compare the models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://towardsdatascience.com/chi-squared-tests-to-compare-two-machine-learning-models-and-determine-whether-they-are-random-2a405fc55181 | |
import numpy as np | |
import pandas as pd | |
from scipy.stats import chi2_contingency | |
data=[[58,7],[11,24]] #Model M1 table | |
#Chi square statistic,pvalue,DOF,expected table | |
stat, p, dof, expected = chi2_contingency(data) | |
print('Chi-square statistic=',stat) | |
print('Pvalue=',p) | |
alpha=0.05 | |
if p < alpha: | |
print('Not a random guesser') | |
else: | |
print('Model is a random guesser') | |
#Chi-square statistic= 32.884319981094166 | |
#Pvalue= 9.780899116984747e-09 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment