ppc64le/linux/: jenkspy-0.4.1 metadata and description

Simple index

Compute Natural Breaks (Fisher-Jenks algorithm)

author_email Matthieu Viry <[email protected]>
classifiers
  • Programming Language :: Python
  • Development Status :: 5 - Production/Stable
  • Operating System :: OS Independent
  • License :: OSI Approved :: MIT License
  • Programming Language :: Python :: 3.7
  • Programming Language :: Python :: 3.8
  • Programming Language :: Python :: 3.9
  • Programming Language :: Python :: 3.10
  • Programming Language :: Python :: 3.11
  • Programming Language :: Python :: 3.12
  • Topic :: Scientific/Engineering
  • Typing :: Typed
  • Environment :: MetaData :: IBM Python Ecosystem
description_content_type text/markdown
dynamic license-file
license MIT License Copyright (c) 2016-2022 Matthieu Viry Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
license_file LICENSE
maintainer_email Matthieu Viry <[email protected]>
project_urls
  • Homepage, https://github.com/mthh/jenkspy
  • Repository, https://github.com/mthh/jenkspy.git
  • Issues, https://github.com/mthh/jenkspy/issues
  • Changelog, https://github.com/mthh/jenkspy/blob/master/CHANGES.rst
requires_dist
  • numpy
requires_python >=3.7
File Tox results History
jenkspy-0.4.1-cp310-cp310-linux_ppc64le.whl
Size
641 KB
Type
Python Wheel
Python
3.10
jenkspy-0.4.1-cp311-cp311-linux_ppc64le.whl
Size
570 KB
Type
Python Wheel
Python
3.11
jenkspy-0.4.1-cp312-cp312-linux_ppc64le.whl
Size
581 KB
Type
Python Wheel
Python
3.12
jenkspy-0.4.1-cp313-cp313-linux_ppc64le.whl
Size
655 KB
Type
Python Wheel
Python
3.13
jenkspy-0.4.1-cp39-cp39-linux_ppc64le.whl
Size
545 KB
Type
Python Wheel
Python
3.9

Jenkspy: Fast Fisher-Jenks breaks for Python

Compute "natural breaks" (Fisher-Jenks algorithm) on list / tuple / array / numpy.ndarray of integers/floats.

The algorithm implemented by this library is also sometimes referred to as Fisher-Jenks algorithm, Jenks Optimisation Method or Fisher exact optimization method. This is a deterministic method to calculate the optimal class boundaries.

Intended compatibility: CPython 3.7+

Wheels are provided via PyPI for Windows / MacOS / Linux users - Also available on conda-forge channel for Anaconda users.

Usage

Two ways of using jenkspy are available:

>>> import jenkspy
>>> import json

>>> with open('tests/test.json', 'r') as f:
...     # Read some data from a JSON file
...     data = json.loads(f.read())
...
>>> jenkspy.jenks_breaks(data, n_classes=5) # Asking for 5 classes
[0.0028109620325267315, 2.0935479691252112, 4.205495140049607, 6.178148351609707, 8.09175917180255, 9.997982932254672]
# ^                      ^                    ^                 ^                  ^                 ^
# Lower bound            Upper bound          Upper bound       Upper bound        Upper bound       Upper bound
# 1st class              1st class            2nd class         3rd class          4th class         5th class
# (Minimum value)                                                                                    (Maximum value)

The .fit and .group behavior is slightly different from jenks_breaks, by accepting value outside the range of the minimum and maximum value of breaks_, retaining the input size. It means that fit and group will use only the inner_breaks_. All value below the min bound will be included in the first group and all value higher than the max bound will be included in the last group.

>>> from jenkspy import JenksNaturalBreaks

>>> x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

>>> jnb = JenksNaturalBreaks(4) # Asking for 4 clusters

>>> jnb.fit(x) # Create the clusters according to values in 'x'
>>> print(jnb.labels_) # Labels for fitted data
... print(jnb.groups_) # Content of each group
... print(jnb.breaks_) # Break values (including min and max)
... print(jnb.inner_breaks_) # Inner breaks (ie breaks_[1:-1])
[0 0 0 1 1 1 2 2 2 3 3 3]
[array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8]), array([ 9, 10, 11])]
[0.0, 2.0, 5.0, 8.0, 11.0]
[2.0, 5.0, 8.0]

>>> print(jnb.predict(15)) # Predict the group of a value
3

>>> print(jnb.predict([2.5, 3.5, 6.5])) # Predict the group of several values
[1 1 2]

>>> print(jnb.group([2.5, 3.5, 6.5])) # Group the elements into there groups
[array([], dtype=float64), array([2.5, 3.5]), array([6.5]), array([], dtype=float64)]

Installation

pip install jenkspy
git clone http://github.com/mthh/jenkspy
cd jenkspy/
pip install .
conda install -c conda-forge jenkspy

Requirements

Motivation: