如何编写Silhouette得分函数作为自定义Keras损失函数?

时间:2019-11-14 09:42:01

标签: keras silhouette

我正在尝试使用Silhouette得分的SKlearn实现编写自定义Keras损失函数。
在调试器模式下运行网络时,在“ training_utils”中,我得到ndim = None而不是ndim = 1。
我想知道我想做的事是否现实并且可以做到?还是我应该开始在TensorFlow中写Silhuoette分数,而不是使用sklearn numpy实现+ py_function来

丢失代码

def loss_fun(y_true, y_pred):
    sil_loss = tf.py_function(
        sklearn.metrics.silhouette_score,
        [y_pred[:, :-1], y_pred[:, -1]],
        tf.float32,
        name='silhouetteScore'
    )
    return tf.expand_dims(sil_loss, axis=1)
return loss_fun

感谢您的反馈和意见!

0 个答案:

没有答案