RandomizedSearchCV
很有用,因为它不会尝试您列出要尝试的所有参数。相反,它显示了一些,并测试他们,看看哪个更好
但是我怎么知道测试了哪些参数呢
例如,在下面的脚本中,测试了n_estimators
、max_features
和max_depth
的哪些组合n_estimator = 10
进行了测试n_estimator = 100
进行了测试
rf = RandomForestRegressor()
n_estimators = [int(x) for x in np.linspace(start=10, stop=2000, num=200)]
max_features = ["auto", "sqrt", "log2"]
max_depth = [int(x) for x in np.linspace(5, 500, num=100)]
random_grid = {
"n_estimators": n_estimators,
"max_features": max_features,
"max_depth": max_depth,
}
randomsearch = RandomizedSearchCV(rf, param_distributions=random_grid, cv=5)
randomsearch.fit(X_train, y_train)
属性
cv_results_
中提供了大量有关搜索的信息。将该dict导入到数据帧中,您将得到测试的每个超参数组合的一行,其中包含超参数值、折叠和平均分数、可选的训练分数、训练时间等相关问题 更多 >
编程相关推荐