user10024395
user10024395

Reputation: 1

How to write a categorization accuracy loss function for keras (deep learning library)?

How to write a categorization accuracy loss function for keras (deep learning library)?

Categorization accuracy loss is the percentage of predictions that are wrong, i.e. #wrong/#data points.

Is it possible to write a custom loss function for that?

Thanks.

Upvotes: 0

Views: 1142

Answers (1)

Christian Hirsch
Christian Hirsch

Reputation: 2056

EDIT

Although Keras allows you to use custom loss function, I am not convinced anymore that using accuracy as loss makes sense. First, the network's last layer will typically be soft-max, so that you obtain a vector of class probabilities rather than the single most likely class. Second, I fear that there will be issues with gradient computation due to lack of smoothness of accuracy.

OLD POST

Keras offers you the possibility to use custom loss functions. To get the accuracy loss, you can take inspiration from the examples that are already implemented. For binary classification, I would suggest the following implementation

def mean_accuracy_error(y_true, y_pred):
    return K.mean(K.abs(K.sign(y_true - y_pred)), axis=-1)

Upvotes: 1

Related Questions