我正在研究这个odds ratios in logistic regression tutorial,并尝试使用scikit learn的logistic回归模块得到完全相同的结果。使用下面的代码,我可以获得系数和截距,但找不到方法来查找教程中列出的模型的其他属性,如对数似然性、比值比、标准误差、z、P>;| z |、[95%配置间隔]。如果有人能告诉我如何用sklearn
包计算它们,我将不胜感激。
import pandas as pd
from sklearn.linear_model import LogisticRegression
url = 'http://www.ats.ucla.edu/stat/mult_pkg/faq/general/sample.csv'
df = pd.read_csv(url, na_values=[''])
y = df.hon.values
X = df.math.values
y = y.reshape(200,1)
X = X.reshape(200,1)
clf = LogisticRegression(C=1e5)
clf.fit(X,y)
clf.coef_
clf.intercept_
你可以通过取系数的指数来得到比值比:
至于其他的统计数据,从scikit learn中不容易获得(在scikit learn中,模型评估主要是使用交叉验证完成的),如果需要它们,最好使用不同的库,例如
statsmodels
。除了@maxymoo的答案之外,要获得其他统计信息,还可以使用
statsmodel
。假设您的数据位于名为DataFrame
的df
中,下面的代码应该显示一个良好的摘要:我不知道使用scikit learn的这种方法,但是statsmodels.a p I.stats中的Table2x2在您的情况下可能很有用,因为它提供了带有3行代码的OR、SE、CI和p值:
相关问题 更多 >
编程相关推荐