当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Multinomial/conditional Logit Regression, Why StatsModel fails on mlogit package example?

问题描述:

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))

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()

I receive the following error

LinAlgError: Singular matrix

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 in statsmodels implements a different version of multinomial logit. AFAICS, it corresponds to nnet multinom in R http://stats.stackexchange.com/questions/186344/r-interpreting-the-multinom-output-using-the-iris-dataset/188426

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.

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: