+-
Python中的随机森林:分类问题的最终概率
在分类问题中,RF分类器根据多数投票(例如,投票结果)给出最终答复.是或否.

另一方面,在Python中,我还可以看到带有事件最终概率的向量,例如0,83.如果我有1000个估计量,每棵树有1000个概率的平均值,那么该概率如何计算?

clf = RandomForestClassifier(max_depth = 4, min_samples_split=2, n_estimators = 200, random_state = 1) 
clf.fit(train[columns], train["churn"]) 
predictions = clf.predict(test[columns]) 
predicted_probs = clf.predict_proba(test[columns]) 
print(predicted_probs) 
test = pd.concat([test, pd.DataFrame(predicted_probs, columns=['Col_0', 'Col_1'])], axis=1) 
最佳答案

is the mean of 1000 probabilities, from each tree?

是的.

向量显示所有树中每个选定类别的平均概率. Scikit RF分类中的最终投票将为所有树的给定输入选择具有最高平均概率的类别.

因此,如果对于双类别数据集,对于给定的样本/输入,C1和C2在分别标记为1和2的树上的概率分别为0.3、0.7和0.5、0.5. C1的平均概率为0.4,而C2的平均概率为0.4.的0.6.

C2是该输入的选定类别,因为它在两棵树上的平均概率最高.

您还可以查看ForestClassifiers的predict方法的源代码.从该方法的__doc__

The predicted class of an input sample is a vote by the trees in
the forest, weighted by their probability estimates. That is,
the predicted class is the one with highest mean probability
estimate across the trees.

概括地说,这是多数表决的一种,表决权重不是树上的班级频率,而是树上的平均值.

点击查看更多相关文章

转载注明原文:Python中的随机森林:分类问题的最终概率 - 乐贴网