Custom metric in Keras when evaluating model performance?

When evaluating the performance of a keras model, these are the available metrics

For regression, I would however like to use e.g. pearson or spearman, such that:

set.seed(13985)
n_dps  = 100
y_pred = runif(n_dps)
y_true = runif(n_dps)
pcc = cor(x = y_pred, y = y_true, method = "pearson")
scc = cor(x = y_pred, y = y_true, method = "spearman")
> pcc
[1] 0.04832645
> scc
[1] 0.09146115

I can't really seem to find a good example on how to do this - Any pointers would be appreciated :+1:

To make custom metrics, It should be composed of use Keras backend-fucntions.

For using correlation function, you may make the correlation function using those back-end functions.

Here is an example of custom metrics.