gpt4 book ai didi

python - 获取某个类别的一列概率值

转载 作者:行者123 更新时间:2023-11-28 22:24:43 25 4
gpt4 key购买 nike

在 sklearn 中使用随机森林进行二元分类时。我知道我可以使用 clf.predict(X) 来获取预测类。当我使用 clf.predict_proba(X) 时,我得到一个如下所示的数组: enter image description here

我认为第一列表示预测的概率?我怎样才能得到一个列,该列是类别为 1 的概率?

最佳答案

来自RandomForest.predict_proba文档:

predict_proba(X)

Predict class probabilities for X.

Returns:
p : [...] The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.

您可以查看 clf.classes_ 属性,查看您的类 1 出现的索引,然后按如下方式访问概率:

prob_class_1 = clf.predict_proba(X)[:, i] 

其中 iclf.classes_ 中类 1 的索引。

关于python - 获取某个类别的一列概率值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46147015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com