gpt4 book ai didi

python - 为岭回归训练 alpha 值

转载 作者:太空宇宙 更新时间:2023-11-04 02:27:54 34 4
gpt4 key购买 nike

我有以下运行简单 Ridge 回归的代码:

for col in cols:                      #zscore normalization
df[col] = (df[col] - df[col].mean())/df[col].std(ddof=0)
y = df['SPXR_{}D'.format(horizon)] #my dependent variable (future market returns)
x = df[cols] #a bunch of variables that predict market returns
model = linear_model.Ridge(alpha=0.5) #ridge regression, guess & check based alpha
res = model.fit(x, y)

我读到过使用数据的前半部分找到 alpha 是最简单的方法,但这怎么可能呢?

最佳答案

让我为您指出 2 个可能的方向。

1) 交叉验证:

  • RidgeCV - 只是一个方便的包装器,结合了 GridSearchCV 和 Ridge。拟合模型并检查属性 _alpha。

2) 贝叶斯方法:

关于python - 为岭回归训练 alpha 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49907180/

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