我目前正在自己做一个项目。对于这个项目,我试图比较多个算法的结果。但是我想确保每个测试的算法都被配置成给出了最好的结果。
因此,我使用交叉验证和测试每一个组合的参数,并选择最佳。
例如:
def KMeanstest(param_grid, n_jobs):
estimator = KMeans()
cv = ShuffleSplit(n_splits=10, test_size=0.2, random_state=42)
regressor = GridSearchCV(estimator=estimator, cv=cv, param_grid=param_grid, n_jobs=n_jobs)
regressor.fit(X_train, y_train)
print("Best Estimator learned through GridSearch")
print(regressor.best_estimator_)
return cv, regressor.best_estimator_
param_grid={'n_clusters': [2],
'init': ['k-means++', 'random'],
'max_iter': [100, 200, 300, 400, 500],
'n_init': [8, 9, 10, 11, 12, 13, 14, 15, 16],
'tol': [1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6],
'precompute_distances': ['auto', True, False],
'random_state': [42],
'copy_x': [True, False],
'n_jobs': [-1],
'algorithm': ['auto', 'full', 'elkan']
}
n_jobs=-1
cv,best_est=KMeanstest(param_grid, n_jobs)
但现在是消磨时间。我想知道这个方法是最好的还是我需要使用不同的方法。
谢谢你的帮助
发布于 2020-02-05 10:41:55
发布于 2020-02-05 10:14:20
除了随机搜索和网格搜索之外,还有一些工具和库可用于更智能的超参数优化。我成功地使用了欧普吞拿,但是很少有更多的。
发布于 2020-02-05 08:49:00
你可以尝试随机搜索代替网格搜索,随机搜索是一种利用超参数的随机组合来为建立的模型找到最佳解的技术。它尝试一系列值的随机组合。为了进行随机搜索优化,该函数在参数空间中按一定数量的随机配置求值。
您可以在滑雪板文档页面上找到详细信息。对随机搜索和网格搜索进行了比较。
我希望你觉得这很有用。
https://stackoverflow.com/questions/60071585
复制相似问题