R 中的 Keras - 使用compile() 的完整指标列表

问题描述 投票:0回答:1

我在 RStudio 中使用 Keras 进行二进制图像分类,但在编译模型时尝试访问包中可用的内置指标的完整列表时遇到问题。我知道 Keras 有内置指标,如 True Positive、True Negative 等。

model1 %>% compile(loss = "binary_crossentropy",
                   optimizer = "rmsprop",
                   metrics = "accuracy")

网上有很多关于如何使用 Python 访问这些内容的信息,但我找不到任何有关 R 的说明。

?compile
仅给出均方误差(
mse
)和
accuracy
作为我可以在
metrics
下输入的示例。如果可以的话,我宁愿避免编写自定义指标(部分原因是我不知道如何从 R 中的模型生成混淆矩阵来编写我自己的自定义指标)。

如有任何帮助,我们将不胜感激。

r tensorflow keras rstudio image-classification
1个回答
0
投票

看看这里:https://keras.posit.co/reference/Metric.html

向下滚动到标题“另请参阅”。在那里,您将找到除示例中使用的指标之外的可用指标。

鉴于上面的参考,以下方法应该适用于调用其他指标:

#------
# Load keras
#------
library(keras3)

#------
# prepare data - define your training and test datasets 
#------
 ...

#------
# compile model with loss function, optimizer, and metrics after sequential setup
# included exemplary metrics: TP, TN, FP, FN
#------
model |> compile(
loss = "binary_crossentropy", 
optimizer = "rmsprop", 
metrics = c(metric_true_positives(), metric_true_negatives(), metric_false_negatives(), metric_false_positives())
)

© www.soinside.com 2019 - 2024. All rights reserved.