简体   繁体   English

Keras相关系数作为R中的度量

[英]Keras correlation coefficient as metric in R

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).有谁知道如何使用相关系数或平方相关系数作为 R 中 keras 的度量(尽管其他语言可能提供线索)。 This is for a CNN that functions similar to an image compressor/decompressor.这适用于功能类似于图像压缩器/解压缩器的 CNN。 Thank you!谢谢!

Also struggling with the same problem.也在为同样的问题而苦苦挣扎。 Here's my go at a custom metric using keras backend functions.这是我使用 keras 后端函数的自定义指标。

  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不过有些不对劲 - 随着时代的增加,相关性下降

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

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