Checking online in here and here I see there are two ways to estimate odds ratio in python but the results are different.
First way:
import scipy.stats as stats
import pandas as pd
df=pd.DataFrame({'c':['m','m','m','m','f','f','f','f'],'l':[1,1,1,0,0,0,0,1]})
ct=pd.crosstab(df.c,df.l)
oddsratio, pvalue = stats.fisher_exact(ct)
Second way:
from sklearn.linear_model import LogisticRegression
df=pd.get_dummies(df,drop_first=True)
clf = LogisticRegression()
clf.fit(df[['c_m']],df[['l']].values)
odds_ratio=np.exp(clf.coef_)
First approach return odds ratio=9 and second approach returns odds ratio=1.9. I am relatively new to the concept of odds ratio and I am not sure how fisher test and logistic regression could be used to obtain the same value, what is the difference and which method is correct approach to get the odds ratio in this case. I would appreciate any hint. thanks.