使用H2O实现网格搜索时服务器错误Water.exceptions.H2OIllegalArgumentException

问题描述 投票:3回答:1

我是一个使用H2O的新手。我试图用GBM运行H2OGridSearch以获得我最好的超参数。我按照H2O-AI Github repo的指示行事。当我尝试回归时,它运作良好,但现在当我尝试分类时,它给了我一个错误。

这是我的代码:

    import h2o
from h2o.automl import H2OAutoML
h2o.init(nthreads = -1, max_mem_size = 8)
data = h2o.import_file("train.csv")
y = "target"
data[y] = data[y].asfactor()
X = data.columns
X.remove(y)
from h2o.grid.grid_search import H2OGridSearch
from h2o.estimators import H2OGradientBoostingEstimator

# hyper_params = {'max_depth' : range(1,30,2)}
hyper_params = {'max_depth' : [4,6,8,12,16,20]} ##faster for larger datasets

#Build initial GBM Model
gbm_grid = H2OGradientBoostingEstimator(
        ## more trees is better if the learning rate is small enough 
        ## here, use "more than enough" trees - we have early stopping
        ntrees=10000,
        ## smaller learning rate is better
        ## since we have learning_rate_annealing, we can afford to start with a 
        #bigger learning rate
        learn_rate=0.05,
        ## learning rate annealing: learning_rate shrinks by 1% after every tree 
        ## (use 1.00 to disable, but then lower the learning_rate)
        learn_rate_annealing = 0.99,
        ## sample 80% of rows per tree
        sample_rate = 0.8,
        ## sample 80% of columns per split
        col_sample_rate = 0.8,
        ## fix a random number generator seed for reproducibility
        seed = 1234,
        ## score every 10 trees to make early stopping reproducible 
        #(it depends on the scoring interval)
        score_tree_interval = 10, 
        ## early stopping once the validation AUC doesn't improve by at least 0.01% for 
        #5 consecutive scoring events
        stopping_rounds = 5,
        stopping_metric = "AUC",
        stopping_tolerance = 1e-4)

#Build grid search with previously made GBM and hyper parameters
grid = H2OGridSearch(gbm_grid,hyper_params,
                         grid_id = 'depth_grid',
                         search_criteria = {'strategy': "Cartesian"})


#Train grid search
grid.train(x=X, 
           y=y,
           training_frame = data)

这是错误:

`

H2OResponseError                          Traceback (most recent call last)
<ipython-input-14-cc0918796da0> in <module>()
     38 grid.train(x=X, 
     39            y=y,
---> 40            training_frame = data)

~\Anaconda3\lib\site-packages\h2o\grid\grid_search.py in train(self, x, y, training_frame, offset_column, fold_column, weights_column, validation_frame, **params)
    207         x = list(xset)
    208         parms["x"] = x
--> 209         self.build_model(parms)
    210 
    211 

~\Anaconda3\lib\site-packages\h2o\grid\grid_search.py in build_model(self, algo_params)
    225             y = y if y in training_frame.names else training_frame.names[y]
    226             self.model._estimator_type = "classifier" if training_frame.types[y] == "enum" else "regressor"
--> 227         self._model_build(x, y, training_frame, validation_frame, algo_params)
    228 
    229 

~\Anaconda3\lib\site-packages\h2o\grid\grid_search.py in _model_build(self, x, y, tframe, vframe, kwargs)
    247         rest_ver = kwargs.pop("_rest_version") if "_rest_version" in kwargs else None
    248 
--> 249         grid = H2OJob(h2o.api("POST /99/Grid/%s" % algo, data=kwargs), job_type=(algo + " Grid Build"))
    250 
    251         if self._future:

~\Anaconda3\lib\site-packages\h2o\h2o.py in api(endpoint, data, json, filename, save_to)
    101     # type checks are performed in H2OConnection class
    102     _check_connection()
--> 103     return h2oconn.request(endpoint, data=data, json=json, filename=filename, save_to=save_to)
    104 
    105 

~\Anaconda3\lib\site-packages\h2o\backend\connection.py in request(self, endpoint, data, json, filename, save_to)
    405                                     auth=self._auth, verify=self._verify_ssl_cert, proxies=self._proxies)
    406             self._log_end_transaction(start_time, resp)
--> 407             return self._process_response(resp, save_to)
    408 
    409         except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as e:

~\Anaconda3\lib\site-packages\h2o\backend\connection.py in _process_response(response, save_to)
    741         # Client errors (400 = "Bad Request", 404 = "Not Found", 412 = "Precondition Failed")
    742         if status_code in {400, 404, 412} and isinstance(data, (H2OErrorV3, H2OModelBuilderErrorV3)):
--> 743             raise H2OResponseError(data)
    744 
    745         # Server errors (notably 500 = "Server Error")

H2OResponseError: Server error water.exceptions.H2OIllegalArgumentException:
  Error: Illegal argument: training_frame of function: grid: Cannot append new models to a grid with different training input


  Request: POST /99/Grid/gbm
    data: {'search_criteria': "{'strategy': 'Cartesian'}", 'hyper_parameters': "{'max_depth': [4, 6, 8, 12, 16, 20]}", 'ntrees': '10000', 'learn_rate': '0.05', 'learn_rate_annealing': '0.99', 'sample_rate': '0.8', 'col_sample_rate': '0.8', 'seed': '1234', 'score_tree_interval': '10', 'stopping_rounds': '5', 'stopping_metric': 'AUC', 'stopping_tolerance': '0.0001', 'training_frame': 'py_1_sid_af08', 'response_column': 'target', 'grid_id': 'depth_grid'}

谁能帮我这个?

python h2o grid-search gbm
1个回答
0
投票

搞定了!我想H2O中有一个错误..在运行它进行分类之前,我运行了3次网格。当我重新启动Anaconda服务器时,上面的代码开始正常工作。

谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.