如何将所有变量从StatsModel(等效于R GLM)中的Python中的逻辑回归用于逻辑回归
我想在Python进行逻辑回归。
我在R中的参考是
model_1 <- glm(status_1 ~., data = X_train, family=binomial)
summary(model_1)
我正在尝试将其转换为Python。但不太确定如何抓住所有变量。
import statsmodels.api as sm
model = sm.formula.glm("status_1 ~ ", family=sm.families.Binomial(), data=train).fit()
print(model.summary())
如何使用所有变量,这意味着在status_1之后我需要输入什么?
I would like to conduct Logistic Regression in Python.
My reference in R is
model_1 <- glm(status_1 ~., data = X_train, family=binomial)
summary(model_1)
I'm trying to convert this into Python. But not so sure how to grab all variables.
import statsmodels.api as sm
model = sm.formula.glm("status_1 ~ ", family=sm.families.Binomial(), data=train).fit()
print(model.summary())
How can I use all variables, which means what do I need to input after status_1?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
statsmodels
使逻辑回归变得非常简单,如下所示:其中
gmat
、gpa
和work_experience
是您独立的变量。statsmodels
makes it pretty straightforward to do logistic regression, as such:Where
gmat
,gpa
andwork_experience
are your independent variables.根据您的问题,我了解您有二项式数据,并且想要使用 logit 作为链接函数创建广义线性模型。另外,正如您在 this 线程(jseabold 的回答)您提到的功能在
patsy
中尚不存在。因此,我将向您展示如何在拥有二项式数据时使用sm.GLM()
函数创建广义线性模型。在这个阶段,我想提一下,我们的因变量应该是一个包含两列的二维数组 statsmodels GLM 函数的帮助 建议:
According to your question, I understand that you have binomial data and you want to create a Generalised Linear Model using logit as link function. Also, as you can see in this thread (jseabold's answer) the feature you mentioned doesn't exist in
patsy
yet. So I will show you how to create a Generalised Linear Model when you have Binomial data by usingsm.GLM()
function.In this phase I want to mention that our dependent variable should be a 2d array with two columns as the help for the statsmodels GLM function suggests: