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)
Metadata
Release files for keras-metrics 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| keras-metrics-1.1.0.tar.gz | 4.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keras_metrics-1.1.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 10.0 kB
Release files / keras-metrics-1.1.0.tar.gz
| Download URL | keras-metrics-1.1.0.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e65b8ace5f4d2100452d3109ef755870f1cfc00d13cb6d8eb96084aee2f5efa2
|
|
BLAKE2b-256 checksum How to use checksums |
3c3946e985d0718d692384c5feb006bb2dcb5846ce60b1ec94db323747b53c90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
|
Release files / keras_metrics-1.1.0-py2.py3-none-any.whl
| Download URL | keras_metrics-1.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
07504def2a674b46e8907c2117ac12c7815c212889c5b31f8c015f7440d279dc
|
|
BLAKE2b-256 checksum How to use checksums |
32c9a87420da8e73de944e63a8e9cdcfb1f03ca31a7c4cdcdbd45d2cdf13275a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
|
Security for keras-metrics 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.