keras-metrics


Namekeras-metrics JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/netrack/keras-metrics
SummaryMetrics for Keras model evaluation
upload_time2019-04-04 13:54:25
maintainer
docs_urlNone
authorYasha Bubnov
requires_python
license
keywords keras metrics evaluation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # Keras Metrics

[![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 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:
```py
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:
```py
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:
```py
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)
```

[BuildStatus]: https://travis-ci.org/netrack/keras-metrics.svg?branch=master



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/netrack/keras-metrics",
    "name": "keras-metrics",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "keras metrics evaluation",
    "author": "Yasha Bubnov",
    "author_email": "girokompass@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3c/39/46e985d0718d692384c5feb006bb2dcb5846ce60b1ec94db323747b53c90/keras-metrics-1.1.0.tar.gz",
    "platform": "",
    "description": "# Keras Metrics\n\n[![Build Status][BuildStatus]](https://travis-ci.org/netrack/keras-metrics)\n\nThis package provides metrics for evaluation of Keras classification models.\nThe metrics are safe to use for batch-based model evaluation.\n\n## Installation\n\nTo install the package from the PyPi repository you can execute the following\ncommand:\n```sh\npip install keras-metrics\n```\n\n## Usage\n\nThe usage of the package is simple:\n```py\nimport keras\nimport keras_metrics as km\n\nmodel = models.Sequential()\nmodel.add(keras.layers.Dense(1, activation=\"sigmoid\", input_dim=2))\nmodel.add(keras.layers.Dense(1, activation=\"softmax\"))\n\nmodel.compile(optimizer=\"sgd\",\n              loss=\"binary_crossentropy\",\n              metrics=[km.binary_precision(), km.binary_recall()])\n```\n\nSimilar configuration for multi-label binary crossentropy:\n```py\nimport keras\nimport keras_metrics as km\n\nmodel = models.Sequential()\nmodel.add(keras.layers.Dense(1, activation=\"sigmoid\", input_dim=2))\nmodel.add(keras.layers.Dense(2, activation=\"softmax\"))\n\n# Calculate precision for the second label.\nprecision = km.binary_precision(label=1)\n\n# Calculate recall for the first label.\nrecall = km.binary_recall(label=0)\n\nmodel.compile(optimizer=\"sgd\",\n              loss=\"binary_crossentropy\",\n              metrics=[precision, recall])\n```\n\nKeras metrics package also supports metrics for categorical crossentropy and\nsparse categorical crossentropy:\n```py\nimport keras_metrics as km\n\nc_precision = km.categorical_precision()\nsc_precision = km.sparse_categorical_precision()\n\n# ...\n```\n\n## Tensorflow Keras\n\nTensorflow library provides the ```keras``` package as parts of its API, in\norder to use ```keras_metrics``` with Tensorflow Keras, you are advised to\nperform model training with initialized global variables:\n```py\nimport numpy as np\nimport keras_metrics as km\nimport tensorflow as tf\nimport tensorflow.keras as keras\n\nmodel = keras.Sequential()\nmodel.add(keras.layers.Dense(1, activation=\"softmax\"))\nmodel.compile(optimizer=\"sgd\",\n              loss=\"binary_crossentropy\",\n              metrics=[km.binary_true_positive()])\n\nx = np.array([[0], [1], [0], [1]])\ny = np.array([1, 0, 1, 0]\n\n# Wrap model.fit into the session with global\n# variables initialization.\nwith tf.Session() as s:\n    s.run(tf.global_variables_initializer())\n    model.fit(x=x, y=y)\n```\n\n[BuildStatus]: https://travis-ci.org/netrack/keras-metrics.svg?branch=master\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Metrics for Keras model evaluation",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/netrack/keras-metrics"
    },
    "split_keywords": [
        "keras",
        "metrics",
        "evaluation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "32c9a87420da8e73de944e63a8e9cdcfb1f03ca31a7c4cdcdbd45d2cdf13275a",
                "md5": "15e20fc5d8a2263d68c1690fc446943e",
                "sha256": "07504def2a674b46e8907c2117ac12c7815c212889c5b31f8c015f7440d279dc"
            },
            "downloads": -1,
            "filename": "keras_metrics-1.1.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "15e20fc5d8a2263d68c1690fc446943e",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 5625,
            "upload_time": "2019-04-04T13:54:24",
            "upload_time_iso_8601": "2019-04-04T13:54:24.384144Z",
            "url": "https://files.pythonhosted.org/packages/32/c9/a87420da8e73de944e63a8e9cdcfb1f03ca31a7c4cdcdbd45d2cdf13275a/keras_metrics-1.1.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c3946e985d0718d692384c5feb006bb2dcb5846ce60b1ec94db323747b53c90",
                "md5": "4eef07ad1a57a62f0577fbc030f7b8c6",
                "sha256": "e65b8ace5f4d2100452d3109ef755870f1cfc00d13cb6d8eb96084aee2f5efa2"
            },
            "downloads": -1,
            "filename": "keras-metrics-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4eef07ad1a57a62f0577fbc030f7b8c6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4400,
            "upload_time": "2019-04-04T13:54:25",
            "upload_time_iso_8601": "2019-04-04T13:54:25.758509Z",
            "url": "https://files.pythonhosted.org/packages/3c/39/46e985d0718d692384c5feb006bb2dcb5846ce60b1ec94db323747b53c90/keras-metrics-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-04-04 13:54:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "netrack",
    "github_project": "keras-metrics",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "keras-metrics"
}
        
Elapsed time: 2.48644s