I just started using keras and would like to use unweighted kappa as a metric when compiling my model. Following the instructions from here, I tried to define my custom metric as follows:
library(DescTools) # includes function to calculate kappa
library(keras)
metric_kappa <- function(y_true, y_pred) {
CohenKappa(y_true, y_pred)
}
model %>% compile(
loss = 'categorical_crossentropy',
optimizer = optimizer_rmsprop(),
metrics = metric_kappa
)
However, there must be something wrong with my definition since I get a segmentation fault. Any idea on how to solve this and how to properly set up a custom metric would be highly appreciated.