简体   繁体   English

OLS 和 IV2SLS 预测意外结果

[英]OLS and IV2SLS prediction unexpected result

I have the following Dataframe:我有以下 Dataframe:

        Price            Quantity  Cost
1       6.979             800.359 1.830
2       7.420             427.363 1.830
3       7.408             486.639 1.830
4       7.613             574.584 1.830
5       8.059             621.247 1.830
6       8.445             498.810 1.830
7       7.864             635.192 1.830
8       9.629             405.185 1.830
9      12.137             364.420 1.830
10     10.945             241.486 1.830

在此处输入图像描述

I ran this:我跑了这个:

ols=sm.OLS(annual['Price'],annual[['Price', 'Quantity']]).fit()
print(ols.predict([1,10]))

(I read here: What is first value that is passed into StatsModels predict function? that I need to add the 1 as constant) (我在这里读到: 传递给 StatsModels 的第一个值是什么预测 function?我需要将 1 添加为常量)

My expected result would be ~340, actual result: [1.]我的预期结果是~340,实际结果:[1.]

I also read that I should include the costs and use the IV2SLS regression like this:我还读到我应该包括成本并像这样使用 IV2SLS 回归:

IV = IV2SLS(annual['Price'],
                  annual[['Price', 'Quantity']],
                  annual[['Price', 'Cost']])

How do I get the prediction here?我如何在这里得到预测?

I tried:我试过了:

IV.fit().predict([1.83,10])

Again expected result ~340 Actual result: [1.83]再次预期结果 ~340 实际结果:[1.83]

Thank you!谢谢!

I believe I have the inputs wrong.我相信我输入错误。 It works like this:它是这样工作的:

resultIV = IV2SLS(annual['menge_fig_adjusted'],
                  annual['Preis_fig'],
                  annual['Cost']).fit()



print(resultIV.predict([10,1.83]).mean())

Result 345结果 345

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM