多元回归按组不工作回归摘要重复相同的结果

2024-04-19 07:26:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用以下帖子中的说明对每个组运行多元回归:How to apply OLS from statsmodels to groupby。我的代码片段如下:

for coins in df_raw.symbol.unique():
    tempdf = df_raw[df_raw.symbol == coins]
    y = (df_raw['Lagged return']).astype(float)
    x1 = (df_raw['Excess daily return']).astype(float)
    x2 = (df_raw['Excess weekly return']).astype(float)
    x3 = (df_raw['Excess monthly return']).astype(float)
    x4 = (df_raw['Trading vol / mkt cap']).astype(float)
    x5 = (df_raw['Std dev']).astype(float)
    x6 = (df_raw['Residual risk']).astype(float)
    result = smf.ols(formula='y ~ x1 + x2 + x3 + x4 + x5 + x6', data=df_raw).fit()
    print(result.params)
    print(result.summary())

然而,当我运行回归时,我得到了完全相同的回归结果,重复数据帧中的每个组(尽管基础数据不同)

Intercept    0.010033
x1          -0.000214
x2          -0.000014
x3          -0.000094
x4          -0.001902
x5          -0.000009
x6          -0.000006

有人能告诉我哪里出错了吗?提前谢谢


Tags: todfrawreturnresultfloatx1x2