2 个回答
你是指预测还是训练过程那?
如果是预测过程,这很简单,sklearn中随机森林可以给出预测概率:
RandomForestClassifier().predict_proba(x)
你得到输入样本x的属于各个类别的概率,然后手动将概率大于0.7的判为正类就可以了,例如对于二分类:
pred_probs = clf.predict_proba(x)
y_pred = [1 if prob >= 0.7 else 0 for prob in pred_probs[:,1]]
多说一点,这个概率是怎么来的那?官方文档中说的非常清楚:
The class probability of a single tree is the fraction of samples of the same class in a leaf.
就是给出的概率其实是训练得到的树中,该叶子节点同样的类别所占的比例。
希望能帮到你~