简体   繁体   English

OLS回归存储问题:零大小数组到归约操作最大值,没有身份

[英]OLS regression storing problem: zero-size array to reduction operation maximum which has no identity

I have a problem with this for loop in python.我在 python 中遇到了这个 for 循环的问题。 I'm trying to iterate the OLS command in a cross-section data where I'have multiple id observed during the same period.我正在尝试在同一时期观察到多个 id 的横截面数据中迭代 OLS 命令。 I want to do a regression for each id of each year, of each month.我想对每年、每个月的每个 id 进行回归。

When i try to run singurlarly the commands they works but in the loop the output is always the same: zero-size array to reduction operation maximum which has no identity .当我尝试单独运行它们的命令时,它们可以工作,但在循环中 output 始终相同:零大小数组到最大缩减操作,没有身份 I have no idea where is the problem in the for loop.我不知道 for 循环中的问题在哪里。 The problem is in the last 8 rows (i have uploaded the other only to make sense to them).问题出在最后 8 行(我上传了另一行只是为了对他们有意义)。 Thanks in advance for your support.预先感谢您的支持。

import pandas as pd\\
import statsmodels.api as sm
import statsmodels.formula.api as smf
from datetime import datetime as dt
from sklearn import linear_model as lm
import numpy as np
data=pd.DataFrame()
data=pd.read_excel('gggg.xlsx', sheet_name='Foglio1')
data['Data']=pd.to_datetime(data['Data'])
data["year"]=data['Data'].dt.year
data["month"]=data['Data'].dt.month

sl=pd.wide_to_long(data, ['R','RM','V','MktCap'], i="Data", j="group_id")


sl["month1"]=sl["month"].shift(-1)
sl['monthindicator'] = np.where(sl['month']!=sl['month1'], 1, 0)
sl["year1"]=sl["year"].shift(-1)
sl['yearindicator'] = np.where(sl['year']!=sl['year1'], 1, 0)


sl['AdjVol']=sl['V']/sl['MktCap']
sl['id']=sl.index.get_level_values('group_id')

for i in range(1,11): 
    for y in range(2012,2020):
        for m in range(1,13):
            Y=sl.loc[(sl['id']==i) & (sl["year"]==y) & (sl["month"]==m), "R"]
            X=sl.loc[(sl['id']==i) & (sl["year"]==y) & (sl["month"]==m), "RM"]
            result = sm.OLS(Y, sm.add_constant(X))
            result=result.fit()
            sl["prediction"] = result.predict()  ```

it usually happens when there is missing value in dataset, you better try df.dropna(how='all') and test it它通常发生在数据集中缺少值时,您最好尝试 df.dropna(how='all') 并对其进行测试

暂无
暂无

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

相关问题 具有Statsmodel ValueError的多个OLS回归:零大小数组到减少操作最大值,没有标识 - Multiple OLS Regression with Statsmodel ValueError: zero-size array to reduction operation maximum which has no identity 零大小数组到没有标识的最大归约操作 - zero-size array to reduction operation maximum which has no identity 零大小数组到没有标识的缩减操作 fmin - zero-size array to reduction operation fmin which has no identity 零大小数组到最大归约操作,对于多输出 U-net 没有标识 - zero-size array to reduction operation maximum which has no identity for multi output U-net 如何修复 keras pad_sequences 中的“零大小数组到没有标识的最大缩减操作” - How to fix "zero-size array to reduction operation maximum which has no identity" in keras pad_sequences SciPy optimize.fmin ValueError:零大小数组到减少操作最大值,没有标识 - SciPy optimize.fmin ValueError: zero-size array to reduction operation maximum which has no identity 如何将 np.max 用于没有 ValueError 的空 numpy 数组:零大小数组到没有标识的缩减操作最大值 - how to use np.max for empty numpy array without ValueError: zero-size array to reduction operation maximum which has no identity 为什么我会得到以及如何解决 ValueError: zero-size array to reduction operation maximum which has no identity - Why am I getting and how to solve ValueError: zero-size array to reduction operation maximum which has no identity 如何修复'ValueError:零尺寸数组到没有身份的归约运算fmin' - How to fix 'ValueError: zero-size array to reduction operation fmin which has no identity' ValueError:零大小数组到没有标识的最小化操作 - ValueError: zero-size array to reduction operation minimum which has no identity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM