Skip to main content

Compute Natural Breaks (Fisher-Jenks algorithm)

Project description

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.6+

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

Version Anaconda-Server Badge Build status GH PyPI download month

Usage

Two ways of using jenkspy are available:

  • by using the jenks_breaks function which takes as input a list / tuple / array.array / numpy.ndarray of integers or floats and returns a list of values that correspond to the limits of the classes (starting with the minimum value of the series - the lower bound of the first class - and ending with its maximum value - the upper bound of the last class).

>>> 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)
  • by using the JenksNaturalBreaks class that is inspired by scikit-learn classes.

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

  • From pypi

pip install jenkspy
  • From source

git clone http://github.com/mthh/jenkspy
cd jenkspy/
python setup.py install
  • For anaconda users

conda install -c conda-forge jenkspy

Requirements :

  • Numpy

  • Only for building from source: C compiler, Python C headers and optionally Cython.

Motivation :

  • Making a painless installing C extension so it could be used more easily as a dependency in an other package (and so learning how to build wheels using appveyor / travis at first - now it uses GitHub Actions).

  • Getting the break values! (and fast!). No fancy functionality provided, but contributions/forks/etc are welcome.

  • Other python implementations are currently existing but not as fast or not available on PyPi.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jenkspy-0.3.2.tar.gz (157.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

jenkspy-0.3.2-cp311-cp311-win_amd64.whl (177.1 kB view details)

Uploaded CPython 3.11Windows x86-64

jenkspy-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (546.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

jenkspy-0.3.2-cp311-cp311-macosx_11_0_arm64.whl (178.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

jenkspy-0.3.2-cp311-cp311-macosx_10_9_x86_64.whl (187.0 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

jenkspy-0.3.2-cp310-cp310-win_amd64.whl (177.8 kB view details)

Uploaded CPython 3.10Windows x86-64

jenkspy-0.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (523.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

jenkspy-0.3.2-cp310-cp310-macosx_11_0_arm64.whl (180.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

jenkspy-0.3.2-cp310-cp310-macosx_10_9_x86_64.whl (188.9 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

jenkspy-0.3.2-cp39-cp39-win_amd64.whl (178.8 kB view details)

Uploaded CPython 3.9Windows x86-64

jenkspy-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (524.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

jenkspy-0.3.2-cp39-cp39-macosx_11_0_arm64.whl (179.9 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

jenkspy-0.3.2-cp39-cp39-macosx_10_9_x86_64.whl (188.4 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

jenkspy-0.3.2-cp38-cp38-win_amd64.whl (179.0 kB view details)

Uploaded CPython 3.8Windows x86-64

jenkspy-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (527.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

jenkspy-0.3.2-cp38-cp38-macosx_11_0_arm64.whl (178.3 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

jenkspy-0.3.2-cp38-cp38-macosx_10_9_x86_64.whl (186.5 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

jenkspy-0.3.2-cp37-cp37m-win_amd64.whl (178.3 kB view details)

Uploaded CPython 3.7mWindows x86-64

jenkspy-0.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (495.5 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

jenkspy-0.3.2-cp37-cp37m-macosx_10_9_x86_64.whl (186.9 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

jenkspy-0.3.2-cp36-cp36m-win_amd64.whl (187.7 kB view details)

Uploaded CPython 3.6mWindows x86-64

jenkspy-0.3.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (496.0 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

jenkspy-0.3.2-cp36-cp36m-macosx_10_9_x86_64.whl (186.8 kB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

File details

Details for the file jenkspy-0.3.2.tar.gz.

File metadata

  • Download URL: jenkspy-0.3.2.tar.gz
  • Upload date:
  • Size: 157.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for jenkspy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 3ff115d90d183cc964f686cd56ed04ddca0976535a601ab8bfd4974211250c80
MD5 fb98be427ef33195fb3f1f8fae9e49e6
BLAKE2b-256 324bb1733f58a792000d989987155a4456a6dff88a036ecb70f0a8cf9afc0b63

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: jenkspy-0.3.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 177.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for jenkspy-0.3.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 80578d5517ef35240254dcf773157f0e90ac440dc01258911d828b93d83811ae
MD5 1eb39d5f32c8237a248e859e6892abe5
BLAKE2b-256 2a55ff3525d7e1e7366e4fd081215b47c409132c48fc0cb3b3bdcccfd2566e37

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef2315ae2fa162709cadcb70c4b4eaa24b58bb139289d8229e073e804c826f9a
MD5 fff34942977f5b79beabbe44cd151d5d
BLAKE2b-256 039e9a533c6657dfbf68c6cd009fcfea96ca808ce2ffd71d4d3304cdec516dc3

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6c1233aef9b25075751e5ed23d574a6c84e906056868221b560a71ab705ce200
MD5 642d60bea59799c5297bb16e97d02cd1
BLAKE2b-256 f2ddb549197b90ec0b71a8690dcb34126a071b9afdc4c86bb99a0805ff0808c9

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ca78332739d3bd0e709a9a1c54ef95a635db2b645d7b4e183a37db35103954aa
MD5 4336b5e65e730885c3be818f98cd6147
BLAKE2b-256 789071d1e24f86d09fb05f9e782ec37d014cb83f7b46a6e3fe12d2d623667fde

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: jenkspy-0.3.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 177.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for jenkspy-0.3.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 48dccdb8e2fd576538175bf5f57bd86a4e9878f99aaa8b9b1bffd57e4adcd59d
MD5 eaf13acd4cfa891279947c04dde1cade
BLAKE2b-256 171b0e6ed79e96c961e0a5950140491397ed2ca53098170d15d68882a0911852

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a7e8083d91483c7491e47ba3a61de509ee11123e3496c9232a8a68de85b1474d
MD5 104b1fbaf55f0b5081a1f8f17fafc3a3
BLAKE2b-256 de8001070058c7db4fdb5c7c04cee071c418def3195d8ed1033e6114409c6b29

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3251a3595740ed269d051412fd18f29020c5af886450e04042631bd59a186c2a
MD5 380537154ac066f096917dd6414d543f
BLAKE2b-256 2dff34112bf3bd06d95797a1f46679d1079fe21bb485504f80abc3580bdf3fbc

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 559de23c99e2e82657fb60f92ec3596155bf456eae5376ccb7a5112b35ced8df
MD5 6fec6532f60e63d72535d5efe905ad1d
BLAKE2b-256 61bf682e443c3f0dbf00a090addeccf792d7d39c4cd311881dbfdacb6af681e4

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: jenkspy-0.3.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 178.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for jenkspy-0.3.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 262518c969c62dcdaeb5cc86216461ba7b84bf73e8974d3c275f31dfddeb5c14
MD5 4d82ffc731cebc20e3085760ba5f5f38
BLAKE2b-256 e4cf87353b0c3de97bb340a74b72859a3b177ed9fbddae0d18c81b86ddb23828

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6eef249e26621d2032bfafe613c0a621b4acda099eac790cfd86938867ea6f32
MD5 fde328c4dbdc9cfed4ac4584135a9015
BLAKE2b-256 3a47dcd63fcff26db4cc64dd84683bd39991fd087775d7504656b0b2734bafce

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cf18a88cf712d500bb8a1e066d1ae82c21d4b79aad2511bfd6d520ab6007455b
MD5 472a6cf14d1a03be3fc278b24ae2d5da
BLAKE2b-256 3557ab6b6ffc177051f773c72339ce1c29bc8b33ae383b9ddb08c40cad788202

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2dbb0f8bb4714b2b9c1e4eedc87e40fb5e2ac5b91102106d38d53242f1adecbc
MD5 1e84d28c98ccd19a9f86d1f9e919c2e3
BLAKE2b-256 99d4a2ea4af60a9dc619217fcf73984721fdf25c8fa88b0c0c252b5aff3333d5

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: jenkspy-0.3.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 179.0 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for jenkspy-0.3.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 283a11591077492cd53509a97bd77b1cf9386853a69b15a0fa10a9ace82b53c2
MD5 2564d3d0778a4d62ee5c8740caddcf7d
BLAKE2b-256 0b5edde6fa39b348ea5e7e8238bf90bdb801deaf698d0e954c0a20f29ff3551a

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 04c01adac0a3d2936bcde3905c25c24072f4909529c15c3124165868e6757da6
MD5 5342d8703ca45600635e4301cf6edea5
BLAKE2b-256 84908193eb28c851ef026e459f58bcf641b3650402851bfcf9f405c2440df5d0

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f749767bb2be68082c43915e678b3ca3d468abcb3bc698b031ea2d204d7a3aca
MD5 165a6132351c7b5636f51fbdec701629
BLAKE2b-256 7c171d7a724543149e42bb980b2dead14c6de452afa2e1c32c70250077cfdac7

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f70b47e8913cc284a10b14e29dd2baec968321e219227ccada7337d3797a18ad
MD5 49c40daa1bc64db4a2e205a4c41e73ae
BLAKE2b-256 579783162db763d11ddec1582e7fa46c56c0008c3a3bd2a1023c69b8c4bea5e4

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: jenkspy-0.3.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 178.3 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for jenkspy-0.3.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 76be2be014b8a1b45f35a0be98ecc1731d3c8712cc8327ed8214d28e97416377
MD5 99e312e4238abca67fb664bd865ac53c
BLAKE2b-256 9173f7fe9823a71872c3eaf9e69117e892f96f0029ad259b54f07e3371104921

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 150610b6ad71e8ebcc48181b7890b570c245dc59df598e14aa088ee16013f650
MD5 e2f8aadbf1cce0a81a54ec75e0fef7bb
BLAKE2b-256 a639f9d11903fd74346770cb50ab653c4bfb5ce9a9176b955b9785650d429459

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 136078eab744e2381adf4c58e127e3ffde63ab2d23e3a817c78971dc44facd1b
MD5 ac7a86322cb0d4e00618aa36ae539e3a
BLAKE2b-256 7e6c3bbf077fbbbe37d1a78ac98c90cf518972c821d39750d36047cb4319cf95

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: jenkspy-0.3.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 187.7 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for jenkspy-0.3.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 d210455301f5085fbc9293b846e3afb6d5ddb338a37ca937399ad20b553c5ce1
MD5 b0ff79ea4bf9692678643bf2aeb1c59c
BLAKE2b-256 97d502ebf25cb1402acdd6512c6d4b4f075d3d90e96d04029984ac6db616134f

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 876d989475efd90f385bd66ee440c8e09409b2add57fa1771d46454976d621eb
MD5 6070eda945f5c3d8d3d0996f8141a42f
BLAKE2b-256 c99594560465c6184cd500649c8d3850788fc91862fed4f7c3344c957a99489c

See more details on using hashes here.

File details

Details for the file jenkspy-0.3.2-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.3.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 20ad0102b17e2766ef95157b3641974d6009fcfea38c1d12bd939d60c2e243fc
MD5 30fcf1d0ae0d6c710f0ac766de7a7aa4
BLAKE2b-256 a2c84e4611c676c505298edf087510814a1f86e3b6d2135a250a66cb115af211

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page