【问题标题】:What is the difference between "predict" and "predict_class" functions in keras?keras 中的“predict”和“predict_class”函数有什么区别?
【发布时间】:2018-12-25 05:21:20
【问题描述】:

keras中predictpredict_class函数有什么区别?

为什么Model 对象没有predict_class 功能?

【问题讨论】:

    标签: keras


    【解决方案1】:

    为什么Model 对象没有predict_class 功能?

    github issue 给出了答案。 (尽管如此,这仍然是一个非常复杂的解释。欢迎任何帮助)

    对于具有多个输出的模型,这些概念是 定义不明确。提供一些东西是个坏主意 单输出的情况,但在其他情况下不是(不一致的 API)。

    对于顺序模型,支持它的原因是 仅向后兼容。

    功能 API 中缺少 Predict_class。

    【讨论】:

      【解决方案2】:

      predict 将返回回归的分数,predict_class 将返回您的预测类别。虽然看起来很相似,但还是有一些区别:

      假设您正在尝试预测图片是狗还是猫(您有一个分类器):

      • predict 将返回您:0.6 只猫和 0.4 只狗(例如)。
      • predict_class 将返回具有最大值的类的索引。例如,如果 cat 为 0.6,dog 为 0.4,则如果 cat 类在索引 0 处,则返回 0)

      现在,假设您正在尝试预测房价(您有一个回归量):

      • predict 将返回预测价格
      • predict_class 在这里没有意义,因为您没有分类器

      TL:DR:对分类器使用predict_class(输出是标签),对回归使用predict(输出是非离散的)

      希望对你有帮助!

      第二个问题,答案是here

      【讨论】:

      • 如果'predict_class'函数用于分类任务,为什么Model对象没有这个功能?
      • 我在浏览stackoverflow时遇到了这个问题,而不是在我编码的时候。我觉得有点奇怪,因为这两个模型处理的任务类型应该是相似的。由于模型对象可以处理分类任务,它应该有'predict_classes'功能。
      • 您能提供更多信息吗?链接可能吗?
      • 你的问题的答案是你给我的帖子的答案,你不明白什么? (试图在这里提供帮助)。这就是答案:The predict_classes method is only available for the Sequential class (which is the class of your first model) but not for the Model class (the class of your second model). With the Model class, you can use the predict method which will give you a vector of probabilities and then get the argmax of this vector (with np.argmax(y_pred1,axis=1)).
      【解决方案3】:

      predict_classes 方法仅适用于 Sequential 类,但不适用于 Model 类 You can check this answer

      【讨论】:

        猜你喜欢
        • 2017-12-11
        • 2017-11-06
        • 2019-05-08
        • 2017-09-29
        • 1970-01-01
        • 1970-01-01
        • 2020-03-16
        • 1970-01-01
        • 2018-08-24
        相关资源
        最近更新 更多