Keras,模型predict_proba的输出 [英] Keras, output of model predict_proba

查看:609
本文介绍了Keras,模型predict_proba的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档中,predict_proba(self, x, batch_size=32, verbose=1)

逐批生成输入样本的类别概率预测.

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

并返回

由Numpy组成的概率预测数组.

A Numpy array of probability predictions.

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

Suppose my model is binary classification model, does the output is [a, b], for a is probability of class_0, and b is the probability of class_1?

推荐答案

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

Here the situation is different and somehow misleading, especially when you are comparing predict_proba method to sklearn methods with the same name. In Keras (not sklearn wrappers) a method predict_proba is exactly the same as a predict method. You can even check it 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

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

So - in a binary classification case - the output which you get depends on the design of your network:

  • 如果网络的最终输出是通过单个S型输出获得的,则predict_proba的输出只是分配给类别1的概率.
  • 如果网络的最终输出是通过应用了softmax函数的二维输出获得的,则predict_proba的输出是一对,其中[a, b]其中a = P(class(x) = 0)b = P(class(x) = 1)
  • if the final output of your network is obtained by a single sigmoid output - then the output of predict_proba is simply a probability assigned to class 1.
  • if the final output of your network is obtained by a two dimensional output to which you are applying a softmax function - then the output of predict_proba is a pair where [a, b] where a = P(class(x) = 0) and b = P(class(x) = 1).

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

This second method is rarely used and there are some theorethical advantages of using the first method - but I wanted to inform you - just in case.

这篇关于Keras,模型predict_proba的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆