Я новичок, использующий H2O.Я пытаюсь запустить H2OGridSearch с GBM, чтобы получить мои лучшие гиперпараметры.Я следую инструкциям, данным на 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'}
Может кто-нибудь помочь мне с этим?