繁体   English   中英

关于H2O的混淆矩阵

[英]Confusion Matrix on H2O

最终编辑:此问题最终发生,因为目标数组是应该表示类别的整数,因此它正在进行回归。 一旦我使用.asfactor()将它们转换为因子,那么下面答案中详述的混淆矩阵方法就可以了


我试图在我的随机森林模型( my_model )上运行一个混淆矩阵,但文档不太有帮助。 这里它说命令是h2o.confusionMatrix(my_model)但在3.0中没有这样的东西。

以下是适合模型的步骤:

from h2o.estimators.random_forest import H2ORandomForestEstimator

data_h = h2o.H2OFrame(data)
train, valid = data_h.split_frame(ratios=[.7], seed = 1234)

my_model = H2ORandomForestEstimator(model_id = "rf_h", ntrees = 400, 
max_depth = 30, nfolds = 8, seed = 25)
my_model.train(x = features, y = target, training_frame=train)
pred = rf_h.predict(valid)

我尝试过以下方法:

my_model.confusion_matrix()

AttributeError: type object 'H2ORandomForestEstimator' has no attribute 
'confusion_matrix'

这个例子中得到了

我试图使用制表符完成找出它可能是什么并尝试过:

h2o.model.confusion_matrix(my_model)

TypeError: 'module' object is not callable

h2o.model.ConfusionMatrix(my_model)

它只输出所有模型诊断,然后输出错误:

H2OTypeError: Argument `cm` should be a list, got H2ORandomForestEstimator 

最后,

h2o.model.ConfusionMatrix(pred)

这给出了与上面相同的错误。

不知道该怎么做,如何查看模型混淆矩阵的结果?

编辑:在Context的问题开头添加了更多代码

请参阅完整参数列表的文档 为方便起见,这里是confusion_matrix(metrics=None, thresholds=None, train=False, valid=False, xval=False)列表confusion_matrix(metrics=None, thresholds=None, train=False, valid=False, xval=False)

以下是如何使用该方法的工作示例:

import h2o
from h2o.estimators.random_forest import H2ORandomForestEstimator
h2o.init()


# import the cars dataset:
# this dataset is used to classify whether or not a car is economical based on
# the car's displacement, power, weight, and acceleration, and the year it was made
cars = h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/junit/cars_20mpg.csv")

# convert response column to a factor
cars["economy_20mpg"] = cars["economy_20mpg"].asfactor()

# set the predictor names and the response column name
predictors = ["displacement","power","weight","acceleration","year"]
response = "economy_20mpg"

# split into train and validation sets
train, valid = cars.split_frame(ratios = [.8], seed = 1234)

# try using the binomial_double_trees (boolean parameter):
# Initialize and train a DRF
cars_drf = H2ORandomForestEstimator(binomial_double_trees = False, seed = 1234)
cars_drf.train(x = predictors, y = response, training_frame = train, validation_frame = valid)
cars_drf.confusion_matrix()
# or specify the validation frame
cars_drf.confusion_matrix(valid=True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM