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

查看:39
本文介绍了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:

  • 如果网络的最终输出是通过单个 sigmoid 输出获得的 - 那么 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天全站免登陆