gpt4 book ai didi

python-3.x - statsmodels 中的 add_constant() 不起作用

转载 作者:行者123 更新时间:2023-12-04 03:19:43 24 4
gpt4 key购买 nike

我尝试将 add_constant() 函数与数据集数组一起使用。在索引 59 它工作(列被创建)但在索引 60 它没有被创建。最初,testmat[59] 返回形状为 (24, 54),而 testmat[60] 返回形状为 (9, 54)。以下是我运行 add_constant 函数时得到的结果:

In: Xnew = sm.add_constant(testmat[59])
Out:
const TRYSIL_PO TRYSIL_TA
6142 1 985.7 271.65
6143 1 984.9 271.85
In: Xnew = sm.add_constant(testmat[60]):
Out:
TRYSIL_PO TRYSIL_TA
6166 983.6 272.75
6167 983.1 272.85

我已经检查了其他来源,但似乎没有解决这个问题。
你能解释一下吗?

最佳答案

如果已经存在方差 = 0 的列,即具有所有相同值的列,则 add_constant() 似乎不起作用。我的数据集就是这种情况(上面的例子中没有提到(54 列))。

解决方法是在 add_constant() 函数中添加 has_constant 选项,如下所示:

sm.add_constant(testmat[60], has_constant='add')

更多信息: http://www.statsmodels.org/dev/generated/statsmodels.tools.tools.add_constant.html

关于python-3.x - statsmodels 中的 add_constant() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36532529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com