Does anyone know how to use the correlation coefficient or squared correlation coefficient as a metric in keras in R (although other languages may provide clues). This is for a CNN that functions similar to an image compressor/decompressor. Thank you!
Also struggling with the same problem. Here's my go at a custom metric using keras backend functions.
metric_correlation <-
custom_metric("correlation",
function(y_true, y_pred){
k_sqrt(k_sum((y_pred-k_mean(y_pred))*(y_true-k_mean(y_true)))/length(y_true))/
k_sqrt(k_var(y_true))/k_sqrt(k_var(y_pred))
})
model %>% compile(loss = 'mean_squared_error', optimizer = 'adam',metrics = metric_correlation)
Something is amiss though - correlation drops as the epochs increase
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.