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.
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 class as interface (it requires NumPy and it 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.
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(4) # Asking for 4 clusters
>>> jnb.fit(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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file jenkspy-0.2.4.tar.gz
.
File metadata
- Download URL: jenkspy-0.2.4.tar.gz
- Upload date:
- Size: 73.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0ca722b940b4c097207b20290994fabdd8dda05c09ff40198de78f9109fbb26 |
|
MD5 | 27ff606eea6825b556c0fe0fde3a806f |
|
BLAKE2b-256 | a2ebc1f9a3221f832fcb41ad2c59d514f2658c22eb06149903fadf8b84051bfa |
File details
Details for the file jenkspy-0.2.4-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 43.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cb4af206045a2184865acc8f7277a59d6f95da41184b306e7cb1c6b66c7ebf0 |
|
MD5 | 2034433bf3c0c83254cddc0176271a25 |
|
BLAKE2b-256 | 982dfa8b133c52163d2444143746ab81c5bb3a3c990179d26543c50dab1f6b65 |
File details
Details for the file jenkspy-0.2.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 76.7 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 319eedf2cb5f974f6e38fc94f286039d4d6c6472d5d4fbb44c195347b2db738f |
|
MD5 | 33339b3776e4cc5a583ce8218337d2ec |
|
BLAKE2b-256 | ba59c4e7deb72c6e6b6af442e304be42c800c56205935ef24fbae5eaa071f866 |
File details
Details for the file jenkspy-0.2.4-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 41.7 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b949a0fefbe6c77d45293420351e449e4fb265b709f02bd9e9fbf05ccd7a9b66 |
|
MD5 | bb8cd317fd590a80ba078be8a151f11e |
|
BLAKE2b-256 | f872e4c6fdbaff60f40cc461c540e6a6337155de290d09f26adc80a6900d29e3 |
File details
Details for the file jenkspy-0.2.4-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 43.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf59a43c6be283c98e233a086d4bcd8f3b9244837da0f7fde4078188690290ad |
|
MD5 | 56ad61bdc7a057bfedc27e7e3b27a4f5 |
|
BLAKE2b-256 | 112cd326c1220974cc84ce96efa3488f606af7bf5dce292062d980200f986b9d |
File details
Details for the file jenkspy-0.2.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 76.5 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff531160f6779b55e48367dd1abc86542dfed47f7b27f9017ce4d0290bab29d9 |
|
MD5 | 9e305177573b9056d229608e624d0f09 |
|
BLAKE2b-256 | 61a9dc0c3f8b1b88d82d8b80461cc347038d94efca26fce96200bc4843612ff1 |
File details
Details for the file jenkspy-0.2.4-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 41.7 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e006dd09a2b669f8862315fc6ce9e1a3ad396748fcf49010f2bea7c948fd9988 |
|
MD5 | 86c3b7e47359d9b4bde8da7a035cbf1f |
|
BLAKE2b-256 | d163bf177f63e1c0664eae0c1588316e452f0508020cd5bcfbe52008467e34a8 |
File details
Details for the file jenkspy-0.2.4-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 43.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29244329c83c64c850667f149f8a860eea5beacdc76b465bfeda6a1db71910fc |
|
MD5 | d79c059f2d209cfb59a50d6dc91fc956 |
|
BLAKE2b-256 | a754d578f41f5e99c08254eac1166141a935312dc7f83190fb0a85684028fd53 |
File details
Details for the file jenkspy-0.2.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 77.0 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3337e0520d920d5ca80f3ec7efd7a74383677ff771f2c3e98f6af00c3fc2550 |
|
MD5 | 1328195117137ba3f9c22dd8b7d18a43 |
|
BLAKE2b-256 | 0af3faedb0e573d8d19793e8e723211e21a8df2f23407e88b59fdc8475147bcb |
File details
Details for the file jenkspy-0.2.4-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 41.7 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 667e847dfe5de75536db0b81548dc55bc991a25b11decafde739c6d9316e410c |
|
MD5 | 1bf41d077a6d51f2f5d40d19bc713aa7 |
|
BLAKE2b-256 | 7267881e04ab12d1b18c36d2104b9924109bf6e475a25256c348d0f9b50a7ef5 |
File details
Details for the file jenkspy-0.2.4-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa8d2119821fe489f8876340776ce4550e65fb8af106a7aaea32abcbcac85c11 |
|
MD5 | 8894b67a058351add104be96b2cf24d1 |
|
BLAKE2b-256 | 06d82d390c3fa25566305da289f506e2ed35b93771ee7fac3a9897e4ebcc5f22 |
File details
Details for the file jenkspy-0.2.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 75.9 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 147bd27e4c7751d8ec02029473042647c7d06c4ff27a3d2bab7689af1f521945 |
|
MD5 | 173983577e905d1979b042602d6587b8 |
|
BLAKE2b-256 | fa02c5b4293dea35878d49b0654d6c914d53d86149c3851c26aa66b03287cfa3 |
File details
Details for the file jenkspy-0.2.4-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 41.7 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 282fdbe1f082d176a0ab597d5fbdae611a6c9d21761aa211ea47edd8d4ce3bbd |
|
MD5 | 460ef3d9b1deb76df52e8055f9207ed2 |
|
BLAKE2b-256 | 903f576f116c25267842ca2a19da5194c42ae667acb6dbb77e812a49e8d78df2 |
File details
Details for the file jenkspy-0.2.4-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 45.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | daabcd6864cdc3a1305f63c96a8c976aad5fd36c89dfd730de65b834d506b2a7 |
|
MD5 | 4c8d8a789c9433b36b4f2c8836938331 |
|
BLAKE2b-256 | fce05a478bf6c576615b81151a5ee016f7105209f626d159113c297506c2acee |
File details
Details for the file jenkspy-0.2.4-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 74.8 kB
- Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9944f5a06430e43897f8abbc246205f00c037b1a7bd9c881ad6bd0e716263b89 |
|
MD5 | 9bae8b9b76c10b597c15a73e00b289a6 |
|
BLAKE2b-256 | 6c2c41955a0d06c79ca427811a4f2d2c4a4ac1af134dce55177895c5081475a8 |
File details
Details for the file jenkspy-0.2.4-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: jenkspy-0.2.4-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 41.6 kB
- Tags: CPython 3.6m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6804532951d0ea707829620043c30c0ed97dbf62cfe7473d988589e97f5cad15 |
|
MD5 | 12af951cb8b54031e7f63cfe428d6f08 |
|
BLAKE2b-256 | 0d926c2da7577a8fd8cefbae5b5bde279e7afece8aecc8b07d3c388f0512eb0e |