python - 使用 sklearn RandomizedSearchCV 进行 H2o 参数搜索
问题描述
我正在尝试使用 sklearn 为 h2o 模型优化最佳参数RandomizedSearchCV
。代码(取自本文档):
from sklearn.model_selection import RandomizedSearchCV
from sklearn.pipeline import Pipeline
from h2o.estimators.gbm import H2OGradientBoostingEstimator
iris_df = h2o.import_file(path="iris.data")
params = {
"gbm__ntrees": [10,20],
"gbm__max_depth": [1,2,3],
"gbm__learn_rate": [0.1,0.2]
}
pipeline = Pipeline([("gbm", H2OGradientBoostingEstimator(distribution="gaussian"))])
random_search = RandomizedSearchCV(pipeline, params,
n_iter=5,
scoring="roc_auc",
random_state=42,
n_jobs=1)
random_search.fit(iris_df[1:], iris_df[0])
但它给了我以下错误:
ValueError: Unexpected __getitem__ selector: <class 'numpy.ndarray'> <class 'numpy.ndarray'>
.
我尝试了不同的数据集,也尝试通过pandas.DataFrame
而不是h2o.frame
,它给出了以下内容:
AttributeError: 'DataFrame' object has no attribute 'cbind'
怎么了?h2o
现在不兼容sklearn
?
解决方案
看起来您正在关注较旧的文档。H2O 有自己的随机网格搜索方法。见下文。
#GBM hyperparameters
gbm_params = {'ntrees': [10, 20], 'max_depth': [1, 2, 3], 'learn_rate': [0.1, 0.2]}
# Search criteria
search_criteria = {'strategy': 'RandomDiscrete', 'max_models': 5, 'seed': 42}
# Train and validate a random grid of GBMs
gbm_grid = H2OGridSearch(model=H2OGradientBoostingEstimator(distribution="gaussian"), grid_id='gbm_grid', hyper_params=gbm_params, search_criteria=search_criteria)
gbm_grid.train(x=predictor_columns, y=response_column, training_frame=iris_df)
有关更多信息,请参阅文档。
推荐阅读
- javascript - 如何修复获取json参数并将其发送到url的java脚本函数
- delphi - 挂钩 Delphi TReader.OnFindComponentClass
- java - 无法使用 zipOutputStream 在 java 中压缩文件?
- spring-boot - WebClient 首次请求缓慢的解决方法
- java - 接口与单例中的全局变量
- php - 我如何在我的 laravel5.7 网站中添加 Metas,如标题、描述、关键字
- javascript - 如何使用向量施加不同的力?
- math - Julia - 数组的绝对值
- android - 尝试使用 SharedPreferences 更改颜色,但方法不正确
- asp.net - 如何修复未映射的成员?