Python中Statsmodels和LogisticRegression之间的区别是什么?

Python中Statsmodels和LogisticRegression之间的区别是什么?,python,scikit-learn,logistic-regression,statsmodels,kaggle,Python,Scikit Learn,Logistic Regression,Statsmodels,Kaggle,我是Python的新手。我正在kaggle.com上完成泰坦尼克号任务。 有人能给我解释一下这样做的区别吗 from sklearn.linear_model import LogisticRegression X2=train[['male']] y2=train['Survived'] logmodel = LogisticRegression() logmodel.fit(X2,y2) print(logmodel.coef_,logmodel.intercept_) 这样: from

我是Python的新手。我正在kaggle.com上完成泰坦尼克号任务。 有人能给我解释一下这样做的区别吗

from sklearn.linear_model import LogisticRegression
X2=train[['male']]
y2=train['Survived']
logmodel = LogisticRegression()
logmodel.fit(X2,y2)
print(logmodel.coef_,logmodel.intercept_)
这样:

from patsy import dmatrices
import statsmodels.api as sm 
y3, X3 = dmatrices( 'Survived ~ male', data=train, return_type='dataframe')
mod = sm.Logit(y_train2, X3)
res = mod.fit()
print (res.summary())
我希望得到相同的截距和系数。但我第一次看到log.reggression,第二次看到:

系数=-2.36631709截距=1.04454658

对于第二个问题:

系数=-2.4676截距=1.1141


为什么系数和截距不同提前谢谢

原因有很多。最突出的是训练方法和默认超参数设置。Thnx,但是,您能更清楚地解释您的答案吗?)在
sm.Logit(…)
中,您的代码中的
y\u train2
是什么?Vivek Kumar,对不起,我的勘误表,当然不是“y2\u train”必须是“y3”。