如何在H2O随机森林或其他二进制分类器中指定肯定类? [英] How do I specify the positive class in an H2O random forest or other binary classifier?
问题描述
我正在使用Python在H2O中构建二进制分类模型。我的 y值是好和不好。我需要使用ok =否定类别= 0和bad =肯定类别= 1来计算指标。但是,我看不到有任何方法可以在H2O中进行设置。例如,以下是预测和混淆矩阵的输出:
I am building a binary classification model in H2O with Python. My 'y' values are 'ok' and 'bad'. I need the metrics to be computed with ok = negative class = 0 and bad = positive class = 1. However, I do not see any way to set this in H2O. For example here is the output of the predictions and confusion matrix:
confusion matrix
bad ok Error Rate
bad 3859 631 0.1405 (631.0/4490.0)
ok 477 1069 0.3085 (477.0/1546.0)
Total 4336 1700 0.1836 (1108.0/6036.0)
>>> predictions.head(10)
predict bad ok
0 bad 0.100604 0.899396
1 bad 0.100604 0.899396
2 bad 0.112232 0.887768
3 ok 0.068917 0.931083
4 ok 0.089706 0.910294
5 ok 0.089706 0.910294
6 ok 0.089706 0.910294
7 bad 0.126182 0.873818
8 bad 0.126182 0.873818
9 ok 0.092306 0.907694
H2O似乎是根据标签中的字母顺序任意确定的。如果我将标签更改为 ok和 sad,这就是我得到的:
H2O seems to arbitrarily decide based on alphabetical order among the labels. If I change the labels to 'ok' and 'sad' here is what I get:
confusion matrix
ok sad Error Rate
ok 798 732 0.4784 (732.0/1530.0)
sad 211 4381 0.0459 (211.0/4592.0)
Total 1009 5113 0.1540 (943.0/6122.0)
>>> predictions.head(10)
predict ok sad
0 sad 0.215206 0.784794
1 sad 0.211073 0.788927
2 sad 0.211073 0.788927
3 ok 0.236190 0.763810
4 ok 0.241641 0.758359
5 ok 0.241641 0.758359
6 ok 0.236099 0.763901
7 sad 0.162072 0.837928
8 sad 0.162072 0.837928
9 sad 0.206146 0.793854
必须有一种方法可以以编程方式设置哪个标签是正类别,哪个标签是负类别?
There must be a way to programmatically set which label is the positive class and which is the negative class?
推荐答案
如果 df
是您的H2O框架,则 df ['y'] = df ['y']。relevel('ok')
应将'ok'设置为0级。请参见 http://docs.h2o.ai/h2o/latest-stable/h2o-py/docs/frame .html#h2o.frame.H2OFrame.relevel
If df
is your H2O Frame then df['y'] = df['y'].relevel('ok')
should set 'ok' to level 0. See http://docs.h2o.ai/h2o/latest-stable/h2o-py/docs/frame.html#h2o.frame.H2OFrame.relevel
这篇关于如何在H2O随机森林或其他二进制分类器中指定肯定类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!