【问题标题】:h2o python balance classesh2o python平衡类
【发布时间】:2018-03-14 07:53:59
【问题描述】:

我在为 H2ORandomForestEstimator 实现简单平衡时遇到问题,我正在尝试重现 Darren Cook 用 R 编写的书中的一个简单示例('Practical Machine Learning with H2O - 第 107 页)。

在处理 Iris 数据集时,首先我人为地不平衡目标变量,切掉了保留前 120 行的大部分Virginica。

然后我构建了 3 个模型,一个是普通模型,一个是我将 balance_classes 设置为 True,最后一个是我将 balance_classes 设置为 True,然后我输入了一个 class_sampling_factors 列表以对弗吉尼亚模型进行过采样。列表为 [1.0,1.0,2.5],指的是按字母顺序排列的列。

我训练它们,然后为每个训练输出混淆矩阵。

我期望第一个输出不平衡,后两个输出平衡,而我总是得到相同的结果。我查了the documentation example in Python,看不出有什么问题(我可能也累了)。

这是我的代码:

data_unb = data[1:120,:]  # messing up with target variable
train, valid = data_unb.split_frame([0.8], seed=12345)

m1 = h2o.estimators.random_forest.H2ORandomForestEstimator(seed=12345)
m2 = h2o.estimators.random_forest.H2ORandomForestEstimator(balance_classes=True, seed=12345)
m3 = h2o.estimators.random_forest.H2ORandomForestEstimator(balance_classes=True, class_sampling_factors=[1.0,1.0,2.5], seed=12345)

m1.train(x=list(range(4)),y=4,training_frame=train,validation_frame=valid,model_id='RF_defaults')
m2.train(x=list(range(4)),y=4,training_frame=train,validation_frame=valid,model_id='RF_balanced')
m3.train(x=list(range(4)),y=4,training_frame=train,validation_frame=valid,model_id='RF_class_sampling',)

m1.confusion_matrix(train)
m2.confusion_matrix(train)
m3.confusion_matrix(train)

这是我的输出:

my confusion matrices (wrong)

这是我的预期输出。

expected confusion matrices

我明显错过了什么?提前致谢。

【问题讨论】:

    标签: python machine-learning h2o


    【解决方案1】:

    你没有错过任何东西。 offset_column 在 H2O 随机森林中可用,但实际上并没有功能。该错误记录在 here 中,应该在 H2O 的下一个稳定版本中修复。很抱歉造成混乱!

    它应该适用于其余的 H2O 算法(XGBoost 除外)。例如,如果您想尝试 GBM,您会看到它在工作。

    【讨论】:

    • 这个错误只会影响 Python 吗?或者这是在某个时候在 Java 端引入的错误? (书中的示例是在 R 中完成的,并且是使用 H2O 3.10,IIRC 完成的。)
    • 感谢您的回答,但我的问题涉及混淆矩阵中的 Rate 列,即使对于平衡模型,我也得到了不平衡的 Iris-virginica 数量。无论如何,我设法使用 model.model_performance(train=True) 输出了正确的 CM,现在的问题是我从 model.confusion_matrix(train) 得到的矩阵和从 .model_performance(train=) 得到的矩阵有什么区别True) 方法?
    • @Daniele 这听起来值得作为一个新问题提出。 (如果您认为它是同一个问题的一部分,您可以编辑您的问题并显示附加代码;但是一旦问题得到答案,这可能会令人困惑。)
    • @Daniele 这是一个已知的混淆矩阵错误:0xdata.atlassian.net/browse/PUBDEV-5243 这可能是您遇到的问题,但此代码不起作用model.confusion_matrix(train) 所以我无法复制您的内容重新做。查看 JIRA,并将您的差异添加为评论。谢谢!
    • @DarrenCook 它显然没有在 RF 的后端实现......我们只是注意到了这一点。
    猜你喜欢
    • 2017-01-05
    • 2019-09-20
    • 2018-05-08
    • 2019-01-29
    • 2017-08-28
    • 2018-03-24
    • 2020-03-11
    • 2020-10-24
    • 1970-01-01
    相关资源
    最近更新 更多