Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/netrack/keras-metrics
Metrics for Keras. DEPRECATED since Keras 2.3.0
https://github.com/netrack/keras-metrics
deprecated keras machine-learning python
Last synced: 27 days ago
JSON representation
Metrics for Keras. DEPRECATED since Keras 2.3.0
- Host: GitHub
- URL: https://github.com/netrack/keras-metrics
- Owner: netrack
- License: mit
- Created: 2018-05-23T19:54:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-22T08:39:15.000Z (almost 3 years ago)
- Last Synced: 2024-09-27T21:01:18.812Z (about 1 month ago)
- Topics: deprecated, keras, machine-learning, python
- Language: Python
- Homepage:
- Size: 41 KB
- Stars: 165
- Watchers: 7
- Forks: 23
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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][BuildStatus]](https://travis-ci.org/netrack/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:
```sh
pip install keras-metrics
```## Usage
The usage of the package is simple:
```py
import keras
import keras_metrics as kmmodel = 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:
```py
import keras
import keras_metrics as kmmodel = 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:
```py
import keras_metrics as kmc_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:
```py
import numpy as np
import keras_metrics as km
import tensorflow as tf
import tensorflow.keras as kerasmodel = 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)
```[BuildStatus]: https://travis-ci.org/netrack/keras-metrics.svg?branch=master