简体   繁体   English

在 Keras 中为“categorical_crossentropy”选择验证指标

[英]Selecting validation metric for `categorical_crossentropy` in Keras

I am looking at these two questions and documentation:我正在查看这两个问题和文档:

Whats the output for Keras categorical_accuracy metrics? Keras categorical_accuracy 指标的 output 是什么?

Categorical crossentropy need to use categorical_accuracy or accuracy as the metrics in keras? 分类交叉熵需要使用 categorical_accuracy 或 accuracy 作为 keras 中的指标吗?

https://keras.io/api/metrics/probabilistic_metrics/#categoricalcrossentropy-class https://keras.io/api/metrics/probabilistic_metrics/#categoricalcrossentropy-class

For classification of X-Rays images I (15 classes) I do:对于 X 射线图像 I(15 类)的分类,我会:

# Compile a model
model1.compile(optimizer = 'adam', loss = 'categorical_crossentropy', 
metrics = ['accuracy']) 

# Fit the model
history1 = model1.fit_generator(train_generator, epochs = 10, 
steps_per_epoch = 10, verbose = 1, validation_data = valid_generator)

My model works and I have an output:我的 model 工作,我有一个 output:

But I am not sure how to add validation accuracy here to compare results and avoid over/underfitting.但我不确定如何在此处添加验证准确性以比较结果并避免过度/欠拟合。

I hope the following can help you:我希望以下内容可以帮助您:

The use of "categorical_crossentropy" tells me that your labels are a one hot encoding over different classes. "categorical_crossentropy"的使用告诉我你的标签是对不同类的一种热编码。

Let's say you have 15 classes, the correct prediction would be a vector with 14 zeros, and a one at the corresponding index.假设您有 15 个类,正确的预测将是一个包含 14 个零的向量,以及对应索引处的一个。 In this context "accuracy" will be very high as your model will be correctly predicting mostly zero everywhere, so the accuracy should easily be at least 13/15 = 0.86.在这种情况下, "accuracy"将非常高,因为您的 model 将正确预测几乎所有地方都为零,因此准确度应该很容易达到至少 13/15 = 0.86。

A more suitable metric would be "categorical_accuracy" which will give you 1 if the model predicts the correct index, and else 0.更合适的度量标准是"categorical_accuracy" ,如果 model 预测正确的索引,则为 1,否则为 0。

If you have a validation "categorical_accuracy" better than 1/15 = 0.067 (assuming your class are correctly balanced), your model is better than random.如果您的验证"categorical_accuracy"优于 1/15 = 0.067(假设您的 class 正确平衡),则您的 model 比随机更好。

You can find a list of metrics at keras metrics .您可以在keras 指标中找到指标列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM