多项式/条件Logit回归,为什么StatsModel在mlogit软件包示例上失败? [英] Multinomial/conditional Logit Regression, Why StatsModel fails on mlogit package example?

查看:214
本文介绍了多项式/条件Logit回归,为什么StatsModel在mlogit软件包示例上失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重现R中mlogit包的多项式logit回归示例.

I am trying to reproduce an example of a multinomial logit regression of the mlogit package in R.

data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")
#a pure "conditional" model
summary(mlogit(mode ~ price + catch, data = Fish))

要使用statsmodel函数MNLogit重现此示例,我将Fishing数据集导出为csv文件并执行以下操作

To reproduce this example with statsmodel function MNLogit, I export the Fishing data set as a csv file and do the following

import pandas
import statsmodels.api as st
#load data
df = pandas.read_csv("Fishing.csv")
x = df.drop('mode', axis = 1)
y = df['mode']
mdl = st.MNLogit(y, x)
mdl_fit = mdl.fit()  

我收到以下错误

LinAlgError: Singular matrix

我试图找出如何重新组织原始数据集Fishing的方法,因为我知道mlogit包在拟合之前会重新组织数据,但无法确定如何在statsmodel中进行更改.任何帮助将不胜感激.

I have tried to figure out how to re organise the originial data set Fishing, as I know that mlogit package reorganise the data before fitting but can't figure how to change that in statsmodel. Any help would be much appreciated.

推荐答案

MNLogit实现了不同版本的多项式logit. AFAICS,它对应于R https中的nnet多项式://stats.stackexchange.com/questions/186344/r-interpreting-the-multinom-output-using-the-iris-dataset/188426

MNLogit in statsmodels implements a different version of multinomial logit. AFAICS, it corresponds to nnet multinom in R https://stats.stackexchange.com/questions/186344/r-interpreting-the-multinom-output-using-the-iris-dataset/188426

在这种情况下,各个选项的参数不同,但说明变量没有差异.在多选CLogit版本或R中的mlogit版本中,解释变量随选择而不同,但参数是与选择无关的.

In this case, the parameters differ across choices but not the explanatory variables. In the multiple choice CLogit version, or mlogit version in R, the explanatory variables differ across choices but the parameters are choice independent.

CLogit和其他多项logit版本正在等待statsmodels的请求,并且当前在main分支中不可用.

The CLogit and other multinomial logit versions are waiting in pull requests for statsmodels, and are currently not available in the main branch.

这篇关于多项式/条件Logit回归,为什么StatsModel在mlogit软件包示例上失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆