看到错误
TypeError:+不支持的操作数类型:“ NoneType”和“ unicode”
当尝试使用gridsearch在h2o中训练模型并且无法解释原因时。
以下是在错误发生之前打印的输出:
drf Grid Build progress: |████████████████████████████████████████████████| 100%
Errors/Warnings building gridsearch model
Hyper-parameter: col_sample_rate_per_tree, 0.75
Hyper-parameter: max_depth, 5
Hyper-parameter: min_rows, 4096.0
Hyper-parameter: min_split_improvement, 1e-08
Hyper-parameter: mtries, 8
Hyper-parameter: nbins, 8
Hyper-parameter: nbins_cats, 64
Hyper-parameter: ntrees, 96
Hyper-parameter: sample_rate, 0.6320000291
failure_details: None
failure_stack_traces: java.lang.NullPointerException
at hex.tree.SharedTree.init(SharedTree.java:164)
at hex.tree.drf.DRF.init(DRF.java:53)
at hex.tree.SharedTree$Driver.computeImpl(SharedTree.java:207)
at hex.ModelBuilder$Driver.compute2(ModelBuilder.java:222)
at hex.ModelBuilder.trainModelNested(ModelBuilder.java:348)
at hex.ModelBuilder$TrainModelNestedRunnable.run(ModelBuilder.java:383)
at water.H2O.runOnH2ONode(H2O.java:1304)
at water.H2O.runOnH2ONode(H2O.java:1297)
at hex.ModelBuilder.trainModelNested(ModelBuilder.java:364)
at hex.grid.GridSearch.buildModel(GridSearch.java:343)
at hex.grid.GridSearch.gridSearch(GridSearch.java:220)
at hex.grid.GridSearch.access$000(GridSearch.java:71)
at hex.grid.GridSearch$1.compute2(GridSearch.java:138)
at water.H2O$H2OCountedCompleter.compute(H2O.java:1416)
at jsr166y.CountedCompleter.exec(CountedCompleter.java:468)
at jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:263)
at jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974)
at jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1477)
at jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
以及用于创建gridsearch对象的代码
model = h2o.h2o.H2ORandomForestEstimator(
response_column=configs['RESPONSE'],
keep_cross_validation_models=False,
keep_cross_validation_predictions=False
)
random_forest_grid = h2o.h2o.H2OGridSearch(model=model,
hyper_params=configs['HYPERPARAMETER_RANGES'],
search_criteria=configs['SEARCH_CRITERIA'])
.
.
.
max_train_time_hrs = 8
# here is where the ERROR is thrown
random_forest_grid.train(x=training_features, y=training_response,
weights_column='weight',
training_frame=train_u, validation_frame=test_u,
max_runtime_secs=max_train_time_hrs * 60 * 60)
其中引用的configs
是像...这样的字典。
configs = {
.
.
.
'HYPERPARAMETER_RANGES': {
'ntrees': [32, 64, 96, 128], # default 50
'nbins_cats': [16, 32, 64, 128, 512, 1024], # default is 1024
'nbins': [8, 13, 21, 34], # default is 20
'max_depth': [5, 8, 13], # default is 20
'mtries': [-1, 5, 8, 13], # default is -1 for the square root of number of features
'min_split_improvement': [1 * 10 ** -8,
1 * 10 ** -5,
1 * 10 ** -3],
'min_rows': [16, 64, 256, 1024, 4096], # this option specifies the number of observations for a split
'col_sample_rate_per_tree': [0.75, 0.9, 1], # default is 1
'sample_rate': [0.5, 0.6320000291, 0.75] # default is 0.6320000291
},
'SEARCH_CRITERIA': {
'strategy': 'RandomDiscrete',
'max_models': 24,
'seed': 64,
'stopping_metric': 'AUTO', # log-loss
}
}
请注意,gridsearch适用于我正在训练的其他一些DRF模型(具有完全相同的gridsearch超参数和标准范围),并且似乎找不到这些工作版本与此错误版本之间的任何显着差异。为什么可能会在h2o中引发此类错误?任何理论或进一步的调试建议将不胜感激。
答案 0 :(得分:0)
通过检查h2o Flow UI
中的日志找到了错误的原因(我通常会说这是一个很好的h2o调试技巧(因为看起来有些错误只在此打印而不是标准错误输出) )。
06-20 12:39:02.188 172.18.4.64:54321 27694 FJ-1-11 INFO: Building H2O DRF model with these parameters:
06-20 12:39:02.188 172.18.4.64:54321 27694 FJ-1-11 INFO: {"_train":{"name":"py_9_sid_827e","type":"Key"},"_valid":{"name":"py_10_sid_827e","type":"Key"},"_nfolds":0,"_keep_cross_validation_models":false,"_keep_cross_validation_predictions":false,"_keep_cross_validation_fold_assignment":false,"_parallelize_cross_validation":true,"_auto_rebalance":true,"_seed":111,"_fold_assignment":"AUTO","_categorical_encoding":"AUTO","_max_categorical_levels":10,"_distribution":"AUTO","_tweedie_power":1.5,"_quantile_alpha":0.5,"_huber_alpha":0.9,"_ignored_columns":null,"_ignore_const_cols":true,"_weights_column":"weight","_offset_column":null,"_fold_column":null,"_check_constant_response":true,"_is_cv_model":false,"_score_each_iteration":false,"_max_runtime_secs":28800.0,"_stopping_rounds":0,"_stopping_metric":"AUTO","_stopping_tolerance":0.001,"_response_column":"DENIAL","_balance_classes":false,"_max_after_balance_size":5.0,"_class_sampling_factors":null,"_max_confusion_matrix_size":20,"_checkpoint":null,"_pretrained_autoencoder":null,"_custom_metric_func":null,"_export_checkpoints_dir":null,"_ntrees":96,"_max_depth":13,"_min_rows":64.0,"_nbins":13,"_nbins_cats":16,"_min_split_improvement":1.0E-5,"_histogram_type":"AUTO","_r2_stopping":1.7976931348623157E308,"_nbins_top_level":1024,"_build_tree_one_node":false,"_score_tree_interval":0,"_initial_score_interval":4000,"_score_interval":4000,"_sample_rate":0.6320000291,"_sample_rate_per_class":null,"_calibrate_model":false,"_calibration_frame":null,"_col_sample_rate_change_per_level":1.0,"_col_sample_rate_per_tree":1.0,"_binomial_double_trees":true,"_mtries":5}
06-20 12:39:02.189 172.18.4.64:54321 27694 FJ-1-11 ERRR: _weights_column: Weights column 'weight' not found in the training frame
06-20 12:39:02.189 172.18.4.64:54321 27694 FJ-1-11 ERRR: _weights_column: Weights column 'weight' not found in the training frame
事实证明,该问题是由于以下事实造成的:在所使用的H2OFrame中,在网格搜索中分配为用作weights_column
参数的列实际上并不存在。
将尝试减少问题的发帖范围,以便对可能仅根据标题找到此问题的其他人更加敏感(因为控制台中显示的标准错误没有表明具体问题)。