gpt4 book ai didi

python - Keras,模型 predict_proba 的输出

转载 作者:太空狗 更新时间:2023-10-30 01:53:20 25 4
gpt4 key购买 nike

docs , predict_proba(self, x, batch_size=32, verbose=1)

Generates class probability predictions for the input samples batch by batch.

并返回

A Numpy array of probability predictions.

假设我的模型是二元分类模型,输出是[a, b],因为aclass_0的概率,并且bclass_1 的概率?

最佳答案

这里的情况有所不同,并且在某种程度上具有误导性,尤其是当您将 predict_proba 方法与具有相同名称的 sklearn 方法进行比较时。在 Keras(不是 sklearn 包装器)中,方法 predict_probapredict 方法完全相同。你甚至可以检查它here :

def predict_proba(self, x, batch_size=32, verbose=1):
"""Generates class probability predictions for the input samples
batch by batch.
# Arguments
x: input data, as a Numpy array or list of Numpy arrays
(if the model has multiple inputs).
batch_size: integer.
verbose: verbosity mode, 0 or 1.
# Returns
A Numpy array of probability predictions.
"""
preds = self.predict(x, batch_size, verbose)
if preds.min() < 0. or preds.max() > 1.:
warnings.warn('Network returning invalid probability values. '
'The last layer might not normalize predictions '
'into probabilities '
'(like softmax or sigmoid would).')
return preds

因此 - 在二元分类情况下 - 您获得的输出取决于您的网络设计:

  • 如果网络的最终输出是通过单个 sigmoid 输出获得的 - 那么 predict_proba 的输出只是分配给类别 1 的概率。
  • 如果网络的最终输出是通过应用 softmax 函数的二维输出获得的 - 那么 predict_proba 的输出是一对,其中 [a, b] 其中 a = P(class(x) = 0)b = P(class(x) = 1)

第二种方法很少使用,使用第一种方法在理论上有一些优势 - 但我想告诉你 - 以防万一。

关于python - Keras,模型 predict_proba 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41716380/

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