【发布时间】:2015-09-11 08:46:43
【问题描述】:
有没有人使用 Theano 为 Keras 编写自定义 AUC 损失函数?
文档在这里:http://keras.io/objectives/
示例代码在这里:https://github.com/fchollet/keras/blob/master/keras/objectives.py
我看到 pylearn2 中有一个实现,(它实际上是 sklearn 的包装器)但无法将其移植到 Keras 中使用
https://github.com/lisa-lab/pylearn2/blob/master/pylearn2/train_extensions/roc_auc.py
所以我想我的问题是,有人能写出这个函数吗?你愿意分享吗?
【问题讨论】:
-
您可以轻松包装 pylearn2 库中定义的 RocAUCOp。为了与 keras 签名保持一致,它看起来像(未经测试)
def roc_auc(y_true, y_hat): return RocAucScoreOp()(y_true, y_hat) -
我尝试实现他们关于包装 the RocAucScoreOp from pylearn2. 的建议当试图将其作为损失函数传递给 model.compile 时,我收到以下错误:> AttributeError: 'RocAucScoreOp' object has no attribute 'grad' pylearn2 中围绕 RocAucScoreOp 的源代码文档表明它仅用于监控通道,而不是作为优化的目标/损失函数。看来除非有办法定义渐变,否则Keras是不能用的
-
pylearn2版本基本是回调计算AUC。您将无法将 AUC 用作网络的建模目标(在 Keras 或其他地方),因为它不可微。