Scikit learn scikit学习随机分类器概率预测与多数投票

Scikit learn scikit学习随机分类器概率预测与多数投票,scikit-learn,Scikit Learn,在scikit learn In的文档中(摘录如下所示),为什么随机森林的实现与Breiman的原始论文不同?据我所知,Breiman在聚合分类器集合时,选择了分类的多数票(模式),回归的平均票(Liaw和Wiener撰写的论文,他们是原始R代码的维护者,引用如下) 为什么scikit学习使用概率预测而不是多数投票 使用概率预测有什么优势吗 有关章节: 与原始出版物[B2001]相比,scikit学习 实现通过平均分类器的概率来组合分类器 预测,而不是让每个分类器为单个 班级 资料来源:Liaw

在scikit learn In的文档中(摘录如下所示),为什么随机森林的实现与Breiman的原始论文不同?据我所知,Breiman在聚合分类器集合时,选择了分类的多数票(模式),回归的平均票(Liaw和Wiener撰写的论文,他们是原始R代码的维护者,引用如下)

  • 为什么scikit学习使用概率预测而不是多数投票
  • 使用概率预测有什么优势吗
  • 有关章节:

    与原始出版物[B2001]相比,scikit学习 实现通过平均分类器的概率来组合分类器 预测,而不是让每个分类器为单个 班级


    资料来源:Liaw,A.,和Wiener,M.(2002年)。随机森林分类与回归。R news,2(3),18-22。

    这是由Breiman在《套袋预测器》中进行的研究()


    这给出了几乎相同的结果,但使用软投票给出了更平滑的概率。请注意,如果您使用的是完全开发的树,则不会有任何区别。

    此问题现已解决。此处包括以供参考:

    如果需要,最好通过查看代码来回答这些问题 你精通Python

    RandomForestClassifier.predict
    ,至少在当前版本中 0.16.1,预测概率估计值最高的类别,如
    predict\u proba
    所示。()

    predict\u proba
    的文档说明:

    输入样本的预测类概率计算为森林中树木的平均预测类概率。这个 一棵树的类概率是该树样本的分数 一片叶子上的同一类

    与原始方法的区别可能只是
    predict
    提供与
    predict\u proba
    一致的预测。这个 结果有时被称为“软投票”,而不是“硬投票” 布雷曼原始文件中使用的多数票。我不能马上进去 搜索可以找到两种方法性能的适当比较 方法,但在这种情况下,它们似乎都相当合理

    predict
    文档充其量是相当误导的;我已经 服从 修好它

    如果你想做多数票预测,这里有一个函数 去做吧。把它叫做
    predict\u majvote(clf,X)
    而不是
    clf.predict(X)
    。(基于
    预测概率
    ;仅轻微测试,但 我认为这应该行得通。)

    在我尝试过的愚蠢的合成案例中,预测与事实相符
    每次预测
    方法

    from scipy.stats import mode
    from sklearn.ensemble.forest import _partition_estimators, _parallel_helper
    from sklearn.tree._tree import DTYPE
    from sklearn.externals.joblib import Parallel, delayed
    from sklearn.utils import check_array
    from sklearn.utils.validation import check_is_fitted
    
    def predict_majvote(forest, X):
        """Predict class for X.
    
        Uses majority voting, rather than the soft voting scheme
        used by RandomForestClassifier.predict.
    
        Parameters
        ----------
        X : array-like or sparse matrix of shape = [n_samples, n_features]
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.
        Returns
        -------
        y : array of shape = [n_samples] or [n_samples, n_outputs]
            The predicted classes.
        """
        check_is_fitted(forest, 'n_outputs_')
    
        # Check data
        X = check_array(X, dtype=DTYPE, accept_sparse="csr")
    
        # Assign chunk of trees to jobs
        n_jobs, n_trees, starts = _partition_estimators(forest.n_estimators,
                                                        forest.n_jobs)
    
        # Parallel loop
        all_preds = Parallel(n_jobs=n_jobs, verbose=forest.verbose,
                             backend="threading")(
            delayed(_parallel_helper)(e, 'predict', X, check_input=False)
            for e in forest.estimators_)
    
        # Reduce
        modes, counts = mode(all_preds, axis=0)
    
        if forest.n_outputs_ == 1:
            return forest.classes_.take(modes[0], axis=0)
        else:
            n_samples = all_preds[0].shape[0]
            preds = np.zeros((n_samples, forest.n_outputs_),
                             dtype=forest.classes_.dtype)
            for k in range(forest.n_outputs_):
                preds[:, k] = forest.classes_[k].take(modes[:, k], axis=0)
            return preds