import numpy as np
from sklearn.linear_model import Ridge
from sklearn.grid_search import GridSearchCV
prepare a range of alpha values to test
alphas = np.array([1,0.1,0.01,0.001,0.0001,0])
create and fit a ridge regression model
model = Ridge()
grid = GridSearchCV(estimator=model, param_grid=dict(alpha=alphas))
grid.fit(X, y)
print(grid)
summarize the results of the grid search
print(grid.best_score_)
print(grid.best_estimator_.alpha)

本文介绍了一种使用网格搜索(Grid Search)来优化岭回归(Ridge Regression)中正则化参数α的方法。通过定义一系列待测试的α值并利用GridSearchCV工具进行遍历寻优,最终确定了最佳的α值,提高了模型的预测准确性。
2491

被折叠的 条评论
为什么被折叠?



