Skip to content
Metrics for Keras. DEPRECATED since Keras 2.3.0
Branch: master
Clone or download
ybubnov Add deprecation warning (#49)
* Add deprecation warning

This patch adds deprecation warning (since Keras 2.3.0 already provides
all necessary metrics).

* Limit max keras version, bump current version.

* Set max keras version to 2.2.5

* Max tensorflow version is 2.0.0 (not including).

* Keras<2.3.0, Tensorflow<2.0.0
Latest commit de0848c Oct 6, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests Cross-validation with scikit (#46) Sep 2, 2019
.gitignore Allow saving and loading models (ugly hack). (#25) Jan 21, 2019
.travis.yml Remove python 3.3 from travis CI. May 23, 2018
LICENSE.txt Initial commit. May 17, 2018 Add deprecation warning (#49) Oct 6, 2019
requirements.txt Add deprecation warning (#49) Oct 6, 2019
setup.cfg Update the long description. May 23, 2018 Add deprecation warning (#49) Oct 6, 2019

Keras Metrics

Deprecation Warning

Since Keras version 2.3.0, it provides all metrics available in this package. It's preferrable to use metrics from the original Keras package.

This package will be maintained for older version of Keras (<2.3.0).

Build Status

This package provides metrics for evaluation of Keras classification models. The metrics are safe to use for batch-based model evaluation.


To install the package from the PyPi repository you can execute the following command:

pip install keras-metrics


The usage of the package is simple:

import keras
import keras_metrics as km

model = models.Sequential()
model.add(keras.layers.Dense(1, activation="sigmoid", input_dim=2))
model.add(keras.layers.Dense(1, activation="softmax"))

              metrics=[km.binary_precision(), km.binary_recall()])

Similar configuration for multi-label binary crossentropy:

import keras
import keras_metrics as km

model = models.Sequential()
model.add(keras.layers.Dense(1, activation="sigmoid", input_dim=2))
model.add(keras.layers.Dense(2, activation="softmax"))

# Calculate precision for the second label.
precision = km.binary_precision(label=1)

# Calculate recall for the first label.
recall = km.binary_recall(label=0)

              metrics=[precision, recall])

Keras metrics package also supports metrics for categorical crossentropy and sparse categorical crossentropy:

import keras_metrics as km

c_precision = km.categorical_precision()
sc_precision = km.sparse_categorical_precision()

# ...

Tensorflow Keras

Tensorflow library provides the keras package as parts of its API, in order to use keras_metrics with Tensorflow Keras, you are advised to perform model training with initialized global variables:

import numpy as np
import keras_metrics as km
import tensorflow as tf
import tensorflow.keras as keras

model = keras.Sequential()
model.add(keras.layers.Dense(1, activation="softmax"))

x = np.array([[0], [1], [0], [1]])
y = np.array([1, 0, 1, 0])

# Wrap into the session with global
# variables initialization.
with tf.Session() as s:, y=y)
You can’t perform that action at this time.