如何解决我应该如何从这张图片中获得岭回归的建议 alpha 值?
from sklearn.linear_model import Ridge
from sklearn.model_selection import cross_val_score
from matplotlib import pyplot as plt
alpha_space = np.logspace(4,-4,100)
ridge_scores = []
ridge_scores_std = []
# Create a ridge regressor: ridge
ridge = Ridge(normalize=True)
# Compute scores over range of alphas
for alpha in alpha_space:
# Specify the alpha value to use: ridge.alpha
ridge.alpha = alpha
# Perform 10-fold CV: ridge_cv_scores
ridge_cv_scores = cross_val_score(ridge,X,Y,cv=10)
# print( np.mean(ridge_cv_scores))
# Append the mean of ridge_cv_scores to ridge_scores
ridge_scores.append(np.mean(ridge_cv_scores))
# Append the std of ridge_cv_scores to ridge_scores_std
ridge_scores_std.append(np.std(ridge_cv_scores))
# Use this function to create a plot
def display_plot(cv_scores,cv_scores_std):
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(alpha_space,cv_scores)
std_error = cv_scores_std / np.sqrt(10)
ax.fill_between(alpha_space,cv_scores + std_error,cv_scores - std_error,alpha=0.2)
ax.set_ylabel('CV Score +/- Std Error')
ax.set_xlabel('Alpha')
ax.axhline(np.max(cv_scores),linestyle='--',color='.5')
ax.set_xlim([alpha_space[0],alpha_space[-1]])
ax.set_xscale('log')
plt.show()
# Display the plot
display_plot(ridge_scores,ridge_scores_std)
我应该如何从这张图片中获得岭回归的建议 alpha 值? 我不明白 cv score +/- Std error 的含义
参考这篇文章:https://www.kaggle.com/jmataya/regularization-with-lasso-and-ridge
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。