I want to calculate the odds ratio between 2 features, but I got different results as follows:
import numpy as np
x= [1,2,3,2,1]
y= [1,0,1,0,1]
x1 = np.array(x).reshape(-1,1)
y1 = np.array(y).reshape(-1,1)
# method1
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression()
clf.fit(x1,y1)
np.exp(clf.coef_)
# method2
import statsmodels.api as sm
res = sm.Logit(y1, x1).fit()
np.exp(res.params)
I got 0.79 for the first one and 1.11 for the second. I am not sure where I was wrong and really appreciate your help. Thanks.