Skip to main content

Compute Natural Breaks (Jenks algorythm)

Project description

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

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 :

This package consists of a single function (named jenks_breaks) which takes as input a list / tuple / array.array / numpy.ndarray of integers or floats. It 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 random
>>> list_of_values = [random.random()*5000 for _ in range(12000)]

>>> breaks = jenkspy.jenks_breaks(list_of_values, nb_class=6)

>>> breaks
    (0.1259707312994962, 1270.571003315598, 2527.460251085392, 3763.0374498649376, 4999.87456576267)

>>> import json
>>> with open('tests/test.json', 'r') as f:
...     data = json.loads(f.read())
...
>>> jenkspy.jenks_breaks(data, nb_class=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)

This package also support a JenksNaturalBreaks (require NumPy) class as interface (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_bound_. 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. Install using pip install jenkspy[interface] to automatically include NumPy.

>>> from jenkspy import JenksNaturalBreaks

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

>>> jnb = JenksNaturalBreaks()

>>> try:
...     print(jnb.labels_)
...     print(jnb.groups_)
...     print(jnb.inner_breaks_)
>>> except:
...     pass

>>> jnb.fit(x)
>>> try:
...     print(jnb.labels_)
...     print(jnb.groups_)
...     print(jnb.inner_breaks_)
>>> except:
...     pass
[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])]
[2.0, 5.0, 8.0]

>>> print(jnb.predict(15))
3

>>> print(jnb.predict([2.5, 3.5, 6.5]))
[1 1 2]

>>> print(jnb.group([2.5, 3.5, 6.5]))
[array([], dtype=float64), array([2.5, 3.5]), array([6.5]), array([], dtype=float64)]

Installation

  • From pypi

pip install jenkspy
  • To include numpy in pypi

pip install jenkspy[interface]
  • 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*

  • C compiler+

  • Python C headers+

* only for using JenksNaturalBreaks interface

+ only for building from source

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 nor 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.2.2.tar.gz (71.6 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.2.2-cp310-cp310-win_amd64.whl (44.0 kB view details)

Uploaded CPython 3.10Windows x86-64

jenkspy-0.2.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (78.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

jenkspy-0.2.2-cp310-cp310-macosx_10_9_x86_64.whl (41.9 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

jenkspy-0.2.2-cp39-cp39-win_amd64.whl (44.0 kB view details)

Uploaded CPython 3.9Windows x86-64

jenkspy-0.2.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (78.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

jenkspy-0.2.2-cp39-cp39-macosx_10_9_x86_64.whl (41.9 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

jenkspy-0.2.2-cp38-cp38-win_amd64.whl (44.0 kB view details)

Uploaded CPython 3.8Windows x86-64

jenkspy-0.2.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (78.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

jenkspy-0.2.2-cp38-cp38-macosx_10_9_x86_64.whl (41.9 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

jenkspy-0.2.2-cp37-cp37m-win_amd64.whl (44.0 kB view details)

Uploaded CPython 3.7mWindows x86-64

jenkspy-0.2.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (77.7 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

jenkspy-0.2.2-cp37-cp37m-macosx_10_9_x86_64.whl (41.8 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

jenkspy-0.2.2-cp36-cp36m-win_amd64.whl (45.6 kB view details)

Uploaded CPython 3.6mWindows x86-64

jenkspy-0.2.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (76.7 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

jenkspy-0.2.2-cp36-cp36m-macosx_10_9_x86_64.whl (41.7 kB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for jenkspy-0.2.2.tar.gz
Algorithm Hash digest
SHA256 cb3b3d6257fb41299f92e3dd7e013a7f99cebf667670bd8f8b5f21b9df77fb46
MD5 7a5b40562e7213e81b4ac134348bab0b
BLAKE2b-256 790136d431314dc3aa49a2f59e24f3ed2435ce8f670d99f66246398d4c551e20

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jenkspy-0.2.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b6aa97d68f414e2cb23deaeea63289c7a569a3b6cce38b66d2db89e10c416178
MD5 3bdcdb4c7769d2114882b7b73fdfd00e
BLAKE2b-256 c3a4c8e4bdb68236c9457385c6a71ef176d65f5d7d57ae5983429095cb4a6082

See more details on using hashes here.

File details

Details for the file jenkspy-0.2.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.2.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 624007824559abdca41b9e2da4c1c358bb56532086fbcadfea0ead7d63f0ad6f
MD5 987ae61028f90fe33e73b867e0ff9699
BLAKE2b-256 64edece8d110f634f140f0182fdb770815715382977371acf7822fb98ca054d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jenkspy-0.2.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a92b23c47b842748853627be660c0a1d05e92f0a18cc92ae0e1a2ede63a3315c
MD5 ccc4c16c4aa03d9abb12c32654e11755
BLAKE2b-256 b135db35029bc6be5ccfa4eb796a131b8e491ccdd240a036c66df335b560616f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jenkspy-0.2.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f0635763bb571451fbc19ff2f6456dbad9623309aac6e2a8a72de98491cc0397
MD5 b783e5c2aa15a3b1cd4ec7ad27c23d26
BLAKE2b-256 f3df7e4cf87f488ffdb20b4cbc0264ed968d6d65712cb4d11c3ca185f8cb9566

See more details on using hashes here.

File details

Details for the file jenkspy-0.2.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.2.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fec0d0545bebc9b6fbbcfb7e83bbd304e51a31f6e2d898c1e4ff76e11ed8a73a
MD5 0b0c02c18a5e362a9aef40a14b57e5c8
BLAKE2b-256 c06830ccd2f2a559cb9254e2a40455e62c6e71f8d4ed1843a3b990687e60cb2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jenkspy-0.2.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9b13f61619dbdfc339b4f28f0566b61881fb4856bdda96e388dfe06df8fdf9ac
MD5 d8130b75596b485e3c2f74cdcfd3909d
BLAKE2b-256 bd005db30931b987d3c0192624c56280d36916fd78f13d916602c5a76d1535c2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jenkspy-0.2.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 d58fcf559d1487ae4e7e7154cee123abcf775c8c6fee630aba06018910978e0c
MD5 353955ee1ac19fc51411ae479faa3692
BLAKE2b-256 57018335056a5c401f38a71012fd8cfd80b4fd8b98b506d8c937c36101ea229f

See more details on using hashes here.

File details

Details for the file jenkspy-0.2.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.2.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2be6126622c323030b464d8fecb2ecd8cffd5ea1f819438f00ece176c11ebf94
MD5 ef8bb988f42e8a8413db53f521d4ddd0
BLAKE2b-256 b9028a470deaf9f34f995556d4d39b2cc96eb0599bf9283239714664ef96a8b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jenkspy-0.2.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f9bd6e953c077430fecbfce8622cceab01f15ce392a849cfccec6c700b5f7e5e
MD5 bc9a9c6d2b3a0c19c8bce5ffdc7656df
BLAKE2b-256 1d65628ea13deef55952cba9aba3ebbb8c8f50ba6ebc1befb71f0cf31186482d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jenkspy-0.2.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 9efc29ca10048606969767b73f0be82968768d014aaf3476e85ff444148132a7
MD5 aa39343148315b04de5c6992897ad380
BLAKE2b-256 6a1175fe418a5a801f316d76028e4b1d5dee4620ad8fea513f64a5f3dfed88d1

See more details on using hashes here.

File details

Details for the file jenkspy-0.2.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.2.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a2464c152b14cecedd87e745d17084de6cd25ddb30030903a7b45c5c4fd8312d
MD5 1346f1d55a0fa3073ce89cb674bc7f59
BLAKE2b-256 85c2059d2150e02f7cf651f205a9d7e51bb2706290464e05b8de09b356a69855

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jenkspy-0.2.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1150c493fc9b0262bfef5629609af222fce3d893984001f1c3cd8abfc5e89b9d
MD5 6e39b7d9479baf1fa1457e5dbb811c79
BLAKE2b-256 8aa761d758b6d94dea0b22dfb46201ae65725340b393f33bc4c583a0897a7b0a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for jenkspy-0.2.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 125b58530997e9a5c0d3239eeeb6241747feb1224460c005ed0b4bead0d44517
MD5 9d1eb43bd390930eff9903942ce710fd
BLAKE2b-256 3508649a75c6225d03a0cf817695579b26bd4e4dc7e10df249618e603e3c3cd1

See more details on using hashes here.

File details

Details for the file jenkspy-0.2.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for jenkspy-0.2.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0e4e6a687015d0f166955243843abd7c756f3829f4488bb0c2e604fccf2484ae
MD5 99c79d01e277f414a70e2be24d897547
BLAKE2b-256 58331b213df31c0af6ef0ac436006845b7c2b4c9c8ee62bde749377a4c86f28f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jenkspy-0.2.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d46d33bb40bccc24126cd3da5fc9a4e2b97eeb100b15fde3b6c6f5539b33940e
MD5 d099026bd44ce0c2413907ecd179390f
BLAKE2b-256 083b45dad34e9aa554e0d24be5a431537fc117c68ae1f6ac6af438870fa00edb

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