【问题标题】:sklearn: Why is score on a random forest comprising of one tree (so) different from the score computed directly on that tree?sklearn:为什么由一棵树组成的随机森林上的分数与直接在那棵树上计算的分数不同?
【发布时间】:2017-09-29 08:27:43
【问题描述】:

我有一个包含 20 个类和大约 90 个特征的多类分类问题。我正在使用 scikit-learn python 包(版本 0.18.1)中的 RandomForestClassifier。这是我看到的:

> rf1 = RandomForestClassifier(max_features=0.5, n_estimators=1)
> rf1.fit(X_train, y_train)
> print rf1.score(X_test, y_test), rf1.score(X_train, y_train)
0.27868852459 0.740046838407

> print rf1.estimators_[0].score(X_test, y_test), rf1.estimators_[0].score(X_train, y_train)
0.0300546448087 0.0140515222482

> rf1
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
        max_depth=None, max_features=0.5, max_leaf_nodes=None,
        min_impurity_split=1e-07, min_samples_leaf=1,
        min_samples_split=2, min_weight_fraction_leaf=0.0,
        n_estimators=1, n_jobs=1, oob_score=False, random_state=None,
        verbose=0, warm_start=False)

> rf1.estimators_
[DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,
             max_features=0.5, max_leaf_nodes=None,
             min_impurity_split=1e-07, min_samples_leaf=1,
             min_samples_split=2, min_weight_fraction_leaf=0.0,
             presort=False, random_state=2134571240, splitter='best')]

这些分数有何不同?我的射频分类器中有一棵树! 任何指针都会非常有帮助。

我为 rf1 和 rf1.estimators_[0] 绘制了 feature_importances_,它们是相同的,这正是我所期望的。但是分数相差太大了。

【问题讨论】:

    标签: scikit-learn random-forest


    【解决方案1】:

    刚刚想通了。结果是 DecisionTree rf1.estimators_[0] 考虑了从 0 到 19 的类,而 rf1 分类器考虑了从 1 到 20 的类,就像在原始输入中一样。如果我在 DecisionTree 分类器的输出中添加一个,则输出是相同的,正如预期的那样。

    【讨论】:

      猜你喜欢
      • 2019-11-16
      • 2018-06-22
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-28
      • 2018-05-27
      • 2013-10-26
      • 2020-02-15
      相关资源
      最近更新 更多