当尝试获取召回率得分时,例如:
rf_model.recall()
我得到了以下错误:
h2o ValueError: No metric tpr
我可以获取其他指标,例如准确率、AUC、精确率和F1,但无法获取召回率…这可能是一个bug。
如果我运行:
from h2o.model.metrics_base import H2OBinomialModelMetrics as bmmreporter = bmm(rf_model.metric)rf_model.metric('recall')
我得到:
Could not find exact threshold 0.0; using closest threshold found 0.0.
这是怎么回事?
我正在运行的h2o版本是’h2o-3.15.0.3990’。
我按照h2o教程操作:
使用我自己的数据集时,我得到了上述错误。
有什么帮助吗?
另外,如何使用h2o绘制精确率/召回率曲线?
谢谢
回答:
从你的第二个问题开始,Flow有一个精确率/召回率曲线(并且是交互式的)。Flow总是在每个节点的54321端口上运行,即如果你在本地运行h2o,http://127.0.0.1:54321
。
我认为你的数据或模型有一些有趣的地方,当你查看精确率/召回率曲线时就会变得清晰。
在R中,如果你执行str(m)
(其中m
是你的模型),你将看到所有的模型数据。m@training_metrics@metrics$thresholds_and_metric_scores$recall
包含每个阈值的召回率数值。
我还没有弄清楚如何查看Python对象内部,但你的调用是正确的。在我的快速测试中(使用添加了2类枚举列的鸢尾花数据集):
m.metric("recall")
得到:
[[0.8160852636726422, 1.0]]
如果我想获取所有值,可能会像这样:
mDL.metric("recall",thresholds=[x/100.0 for x in range(1,100)])
得到:
Could not find exact threshold 0.01; using closest threshold found 0.010396965719556233.Could not find exact threshold 0.02; using closest threshold found 0.016617060110009896....Could not find exact threshold 0.92; using closest threshold found 0.9469528904679438.Could not find exact threshold 0.93; using closest threshold found 0.9469528904679438.Could not find exact threshold 0.94; using closest threshold found 0.9469528904679438.Could not find exact threshold 0.95; using closest threshold found 0.9469528904679438.Could not find exact threshold 0.96; using closest threshold found 0.9469528904679438.Could not find exact threshold 0.97; using closest threshold found 0.9760293572153097.Could not find exact threshold 0.98; using closest threshold found 0.9787491606489236.Could not find exact threshold 0.99; using closest threshold found 0.9909817370067531.[[0.01, 1.0], [0.02, 1.0], [0.03, 1.0], ... [0.87, 1.0], [0.88, 1.0], [0.89, 0.9850746268656716], [0.9, 0.9850746268656716], [0.91, 0.9850746268656716], [0.92, 0.9850746268656716], [0.93, 0.9850746268656716], [0.94, 0.9850746268656716], [0.95, 0.9850746268656716], [0.96, 0.9850746268656716], [0.97, 0.9701492537313433], [0.98, 0.9552238805970149], [0.99, 0.8955223880597015]]
(我得到这样的不寻常输出是因为它几乎完美地学习了我的数据集 – 我怀疑你也遇到了这种情况?)(我愚蠢地将我的二元列直接设定为输入列之一的函数,没有任何噪声!)