gpt4 book ai didi

python - 统计模型的线性回归问题

转载 作者:行者123 更新时间:2023-12-03 08:49:15 25 4
gpt4 key购买 nike

我有一个看起来像这样的 Pandas df:

   broker-value-current  broker-value-prior      consensus-after  
590.00 510.00 462.55
32.74 31.98 30.72
33.00 30.00 30.04

pctch_broker pctch_consensus pctch_frstrec_eps
15.686275 1.599051 1.421657
2.376485 0.195695 -82.098455
10.000000 0.805369 -82.098455

pctch_frstrec_rev
1.243782
-1.258936
-1.258936

最后几列的创建位置:
 data['pctch_broker'] = ((data['broker-value-current']-data['broker-value-prior'])/data['broker-value-prior'])*100
data['pctch_consensus'] = ((data['consensus-after']-data['consensus-before'])/data['consensus-before'])*100
data['pctch_frstrec_eps'] = ((data['frstrec_eps_announced']-data['frstrec_eps_forecast'])/data['frstrec_eps_forecast'])*100
data['pctch_frstrec_rev'] = ((data['frstrec_rev_announced']-data['frstrec_rev_forecast'])/data['frstrec_rev_forecast'])*100

我也用这一行清除NA:
cleaned_data = data.dropna()

使用scipy统计信息时:
 import statsmodels.formula.api as sm

但是,当我尝试使用以下代码将“pctch_consensus”或“pctch_broker”作为自变量与“pctch_frstrec_rev”或“pctch_frstrec_eps”作为自变量进行回归时:
 reg1 = sm.ols(formula="pctch_consensus ~ pctch_frstrec_rev", data=cleaned_data).fit()

我收到此错误:
RuntimeWarning: invalid value encountered in greater return (S > tol).sum(axis=-1)

最佳答案

发生此问题,因为您的数据框中存在无限。您可以通过在创建新变量时将其除以零来创建这些无穷大。

这应该解决它:

cleaned_data = data.replace([np.inf, -np.inf], np.nan)

关于python - 统计模型的线性回归问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45445413/

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