Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python statsmodels.api Logit给出了一个错误_Python_Python 3.x_Statsmodels - Fatal编程技术网

Python statsmodels.api Logit给出了一个错误

Python statsmodels.api Logit给出了一个错误,python,python-3.x,statsmodels,Python,Python 3.x,Statsmodels,我正在尝试对数据进行Logit回归,但我遇到了一个问题,即每当我尝试拟合数据时,都会出现一个错误: LinAlgError: Singular matrix 我不明白为什么会这样。我的数据帧中不全是0/1,但它只包含1的一小部分。以下是示例: formula = 'wage ~ I( (33 > age) & (age >= 65) ) + I( (50 > age) & (age >= 33) ) + I( (65 > age) & (a

我正在尝试对数据进行Logit回归,但我遇到了一个问题,即每当我尝试拟合数据时,都会出现一个错误:

LinAlgError: Singular matrix
我不明白为什么会这样。我的数据帧中不全是0/1,但它只包含1的一小部分。以下是示例:

formula = 'wage ~ I( (33 > age) & (age >= 65) ) + I( (50 > age) & (age >= 33) ) + I( (65 > age) & (age >= 50) )' 
test = [0 for i in range(3000)]
test[256] = 1
df['wage'] = test
ft = smf.logit(formula=formula, data=df).fit(disp=0)

我怎样才能摆脱这个?你没有办法不适合一个1百分比很小的模型。

你指定交互变量结果的方式真的很奇怪:

  • I((33>年龄)和(年龄>=65))
    :这将是所有的零,你不能有年龄<33岁和年龄>65岁,所以你不能适应这个

  • 如果您将上述值设置为
    I((33>年龄)|(年龄>=65))
    您的模型矩阵仍将是秩亏(即过度确定),因为您的三个预测值都是截距的线性组合

  • 如果你没有截距,它可能会根据你有多少个正类而工作

  • 有。在您的情况下,截取或响应为全零的类将是有问题的

    如果你的目标是找出哪个班级与年龄组有正相关,考虑使用fisher.test

    如果目的是预测。。我认为不平衡的数据无法解决这个问题