h2o-AttributeError:类型对象'ModelBase'没有属性'hit_ratio_table'

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

我正在学习https://github.com/h2oai/h2o-tutorials/blob/master/tutorials/gbm-randomforest/GBM_RandomForest_Example.py的教程

我一直在学习本教程,直到到达hit_ratio_table为止。当我执行“ rf_v1.hit_ratio_table(valid = True)”时,遇到以下错误。

AttributeError                            Traceback (most recent call last)
<ipython-input-21-ff67e4484e12> in <module>
----> 1 rf_v1.hit_ratio_table(valid=True)

~\Anaconda3\lib\site-packages\h2o\utils\metaclass.py in __getattr__(self, name)
    191             if name in self._bci:
    192                 return self._bci[name]
--> 193             return getattr(new_clz, name)
    194 
    195         new_clz = extend_and_replace(clz, __init__=__init__, __getattr__=__getattr__)

~\Anaconda3\lib\site-packages\h2o\utils\metaclass.py in __getattribute__(cls, name)
    233             if attr is not MetaFeature.NOT_FOUND:
    234                 return attr
--> 235         return type.__getattribute__(cls, name)
    236 
    237     def __setattr__(cls, name, value):

AttributeError: type object 'ModelBase' has no attribute 'hit_ratio_table'

我已经尝试使用df.asfactor()将目标转换为因子,但仍然无法正常工作。

python machine-learning h2o
1个回答
0
投票

仅尝试使用下面的示例,它对我来说工作正常,错误可能是由于h2o cluster version,我包括了我的以及h2o.hit_ratio_table的结果

import h2o
h2o.init(
  nthreads=-1,            ## -1: use all available threads
  max_mem_size = "8G")  

from h2o.estimators import H2ORandomForestEstimator
cars = h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/junit/cars_20mpg.csv")

# set the factor:
cars["cylinders"] = cars["cylinders"].asfactor()

# split the training and validation sets:
r = cars[0].runif()
train = cars[r > .2]
valid = cars[r <= .2]

# set the predictors columns, repsonse column, and distribution type:
predictors = ["displacement","power","weight","acceleration","year"]
response_col = "cylinders"
distribution = "multinomial"

# build and train the model:
drf = H2ORandomForestEstimator(nfolds = 3, distribution = distribution)
drf.train(x=predictors, y=response_col, training_frame=train, validation_frame=valid)

# build the hit ratio table:
drf_hit = drf.hit_ratio_table(valid=True)
drf_hit.show()

输出:

H2O cluster uptime: 02 secs
H2O cluster timezone:   Etc/UTC
H2O data parsing timezone:  UTC
H2O cluster version:    3.26.0.10
H2O cluster version age:    3 months and 12 days !!!
H2O cluster name:   H2O_from_python_unknownUser_wggipn
H2O cluster total nodes:    1
H2O cluster free memory:    7.111 Gb
H2O cluster total cores:    4
H2O cluster allowed cores:  4
H2O cluster status: accepting new members, healthy
H2O connection url: http://127.0.0.1:54321
H2O connection proxy:   {'http': None, 'https': None}
H2O internal security:  False
H2O API Extensions: Amazon S3, XGBoost, Algos, AutoML, Core V3, TargetEncoder, Core V4
Python version: 3.6.6 final

k   hit_ratio
0   1   0.988235
1   2   0.988235
2   3   1.000000
3   4   1.000000
4   5   1.000000
© www.soinside.com 2019 - 2024. All rights reserved.