【发布时间】:2018-12-25 05:21:20
【问题描述】:
keras中predict和predict_class函数有什么区别?
为什么Model 对象没有predict_class 功能?
【问题讨论】:
标签: keras
keras中predict和predict_class函数有什么区别?
为什么Model 对象没有predict_class 功能?
【问题讨论】:
标签: keras
为什么
Model对象没有predict_class功能?
github issue 给出了答案。 (尽管如此,这仍然是一个非常复杂的解释。欢迎任何帮助)
对于具有多个输出的模型,这些概念是 定义不明确。提供一些东西是个坏主意 单输出的情况,但在其他情况下不是(不一致的 API)。
对于顺序模型,支持它的原因是 仅向后兼容。
功能 API 中缺少 Predict_class。
【讨论】:
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
【讨论】:
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)).
predict_classes 方法仅适用于 Sequential 类,但不适用于 Model 类 You can check this answer
【讨论】: