Metrics for Keras model evaluation
Project description
Keras Metrics
This package provides metrics for evaluation of Keras classification models. The metrics are safe to use for batch-based model evaluation.
Installation
To install the package from the PyPi repository you can execute the following command:
pip install keras-metrics
Usage
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"))
model.compile(optimizer="sgd",
loss="binary_crossentropy",
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)
model.compile(optimizer="sgd",
loss="binary_crossentropy",
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"))
model.compile(optimizer="sgd",
loss="binary_crossentropy",
metrics=[km.binary_true_positive()])
x = np.array([[0], [1], [0], [1]])
y = np.array([1, 0, 1, 0]
# Wrap model.fit into the session with global
# variables initialization.
with tf.Session() as s:
s.run(tf.global_variables_initializer())
model.fit(x=x, y=y)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for keras_metrics-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aebab161794f20391131d8663118c887556d256e77e81eafcc6047fb8f349a15 |
|
MD5 | 99222eb3fe894742837caf58e58d8799 |
|
BLAKE2b-256 | 970856aa418e7dc8df9f63aad08f9385f4568e4aae82315fecd1862efea15044 |