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
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 :
Only for building from source: C compiler, Python C headers, setuptools and 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
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
Hashes for jenkspy-0.4.0-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7efb5ca93a96cfc3a561569b0673f4bc122f2db45cb42e8610462d2f8a55ca71 |
|
MD5 | e0f8e8b7821d2d8d42d229151341fb29 |
|
BLAKE2b-256 | e26029890f47f0f68dc9ca89d7a05dddc2a074db090720ac0228255710dfd63c |
Hashes for jenkspy-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41ee9bf0cfd2d09801ef90fef1e601c9bf0673c268d4fc37f823353a082c4188 |
|
MD5 | 10104f826ea7ddb267b3ab1312b1679f |
|
BLAKE2b-256 | f0766a1b7c42e4320c18460ae648b7792cff30933fe7ffe6336a93a798994f41 |
Hashes for jenkspy-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18142809feae7e56489a4992036f4e563771f31bdb6aa54b3ecefd9266d35a05 |
|
MD5 | fdcaaef8ac3861ac380af0d5a7024433 |
|
BLAKE2b-256 | 6109287088dd4e619b5261ecadc7d4fe7cfd14940cdd4baeca8c856cdc6b64e7 |
Hashes for jenkspy-0.4.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 147bbaad78845272ccff0c64afb313ad7122d382e6ec7b96f185519ddb0c6c74 |
|
MD5 | b289b121a0e9eea7a69481407dec02d6 |
|
BLAKE2b-256 | 9e3973ccc93dd24a013b63fc2dfeb3ae22517e7147a5e8df03822059523b2670 |
Hashes for jenkspy-0.4.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 240d5a2c73b35c10fc6f8855aefd88b077f286be4eea3157f5db00c748242720 |
|
MD5 | 605a64697a03ffda6667f32dd07e1910 |
|
BLAKE2b-256 | 261edd9cbb0694a36a52fe1d0d63db9627b58c9491f3249aed3fe4b9c6bc79da |
Hashes for jenkspy-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bebada41c67468abf3045e1849694b87865ec58e702a0ab6278b3c8eed30c04 |
|
MD5 | 90936e80aa71fb0881f65cc3373946d4 |
|
BLAKE2b-256 | 7b613e28c1451336ff72d037b627238530243361e13f4146b79ace5fcb8d5fff |
Hashes for jenkspy-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45dd7c78e2f56a31f09c8050962931d832ac9e53df18400f2edab0b611e9d354 |
|
MD5 | 94ce91577da1120fa43a7a5d8f07a3f7 |
|
BLAKE2b-256 | 07db1dafd51ee9ec50bcf19009230228ba61339b713344e71ebfce4344f15e52 |
Hashes for jenkspy-0.4.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b39d813e53857915fa43436b7381b0b7e2f1faf433e4516719301806a5ac5fcd |
|
MD5 | dbb49464fd5f183d8db6a003b7212c15 |
|
BLAKE2b-256 | f0c00be5cb1c83cae742c666d2d9396e2630a53ab6f9da2b12f703acba4cac60 |
Hashes for jenkspy-0.4.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b5cb5aa9410dd496fe68c902a5cf4e9d8328147d957f6ec41b6ed2b62a9a6d8 |
|
MD5 | 5a7ffe3ec6ab93b3227b9b20d35c2c99 |
|
BLAKE2b-256 | 7bcb5e16b434a7a5dc0769404159bdae81b1483fa5059ea53c83ef02f2532dae |
Hashes for jenkspy-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1b42bbe24d5d9dbaffb6f949f07bb80b651711d9247a33000160feb2a1ebfa9 |
|
MD5 | 33174f7439d618480de690c13413a19e |
|
BLAKE2b-256 | c3455782144976395629cb785e1f9e11fd7a03be162eb2f05a85b68383e60a5f |
Hashes for jenkspy-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92f4451be2a68750e9eb87e526db203b32b777888c5f2643782cde1dc69fe089 |
|
MD5 | 2f348e79175f2954ee99331479fceb04 |
|
BLAKE2b-256 | b49a2bd2035242237b5a7d5e2332895796a605b738ff3b825ec06df67b51c340 |
Hashes for jenkspy-0.4.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 946e6df41c0354fab87edfd224195eda0b565c25a710037a95a82137616cebb7 |
|
MD5 | bc23a4f7427ff2e72973002fe49d8a96 |
|
BLAKE2b-256 | e479f82c4534d2b7315eaaf19c36f3adb511c1b116e63aed1797f29dde399736 |
Hashes for jenkspy-0.4.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8185b6d1cc1384ed755cd55075c11e3639e01f20f15b8659ee17416b264e733 |
|
MD5 | 92d604b49ddfcb9e45d2109aec3c3899 |
|
BLAKE2b-256 | 6d08bf30b4743e016d75f90f93ccbbfd126d614fd362cf0c7bed91bc9e731a1c |
Hashes for jenkspy-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8bd64f71d39c0a39b6676c7d51ae9cd575e805d8c69f3828a94d356d95788b1 |
|
MD5 | 3aed5c2afb054c46258b57a5e1805d09 |
|
BLAKE2b-256 | e9dfc06edf5f5f89b98895875ad4cf455719f8ca46abd5ae43633843501de33f |
Hashes for jenkspy-0.4.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c1443a80da94257b7df07bfe174717d189e243309a077767bf2e91602e9e850 |
|
MD5 | 08c191a32d40c59b83e5c73edcfeeb3f |
|
BLAKE2b-256 | 53091b033c3fb56c786affacb6bae3bfa0086d274dad66db0e50b9dc2eaa457c |
Hashes for jenkspy-0.4.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccfeaa6e04a58fe32e7ac4afb78b7daebf0eac395b483788ecd6ff0a94e417e9 |
|
MD5 | d7b0821b8124eafd5955b92696fc0870 |
|
BLAKE2b-256 | 8e1e7b7fb7ea2e7ad4ade8bfce6cbbb2af09e25e5ad539a44a9b4810348e8268 |
Hashes for jenkspy-0.4.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcf0d4d3b74a878d97411e65c06aea03fe29a9d36e24400d8f5c4e718f75f5fe |
|
MD5 | bb8e34ba328b31fddd71d719d0ea773e |
|
BLAKE2b-256 | 56e672a957aa287a666085b8433bb7d4f7deffc66df3deddf3754ebbfdae294b |
Hashes for jenkspy-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c921e7321798052a176caa73b92f7ee0df909798926ede51e77eb9e4abb0bf4 |
|
MD5 | a7b0ccbb0bfeae7ad78d32887011f4a8 |
|
BLAKE2b-256 | 22e0abf8951b7a7c807db8070c0a3018d55cc8da5fc382557d5e8068c164959e |
Hashes for jenkspy-0.4.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e09c32236aa6959a53e8137da127f1fb0d0b5c4c2309a654ddcfa90c92d6dfc1 |
|
MD5 | 7f51c6cd95bc8a9f8570aa174a00adde |
|
BLAKE2b-256 | 4053f70ef6182d9b0ae1a0f3ffc66fcd08c1b0a03bbcdf2f61423be23b0c6267 |
Hashes for jenkspy-0.4.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb688deafd6075d7f923581a77950ed81081f66f32e1815b595108ce6a23d6f7 |
|
MD5 | 5826748198e83c532326bc9af729b7c9 |
|
BLAKE2b-256 | 87fb60d4256ce57ca008d9647088d191858263e125ac88bdca31e8ed4351d59a |
Hashes for jenkspy-0.4.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97792dab9bde06a5d5aec8ed5454f863147eedd0e9661dff1a5da3604138c16d |
|
MD5 | 8feaa26e9515339038db21781e5804e9 |
|
BLAKE2b-256 | 6940086ca4befb826991747577fc07049bcc33f3194a391d97567cdbfbe8ae43 |
Hashes for jenkspy-0.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b5850758dbb0ba6c775342358681260d87e508fef41bca50c335d4d586883bc |
|
MD5 | 643fc02a73d8d9e178c878d0d21ecb2d |
|
BLAKE2b-256 | 05004f2e8aff3e95f034dff9c4756bda3ee8b6ffbe3170843a9c8e0a54bc1568 |
Hashes for jenkspy-0.4.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 858d7a22466c4e86c386e685df1298c03295cecac77e8a4a9cf1dc5dbc386dfa |
|
MD5 | a1601ea121f336b5dcd41086f1a5287e |
|
BLAKE2b-256 | 5f906c607588ddd151578da17f1de75c42b16add2f1177f8b892d7eaa4a61dd7 |
Hashes for jenkspy-0.4.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dea01c8406b648f69fcb18bb89b59a6a2e9a236b909f56e37955d27bc8e98769 |
|
MD5 | 36d74ac363438486f0d4df88ca200f05 |
|
BLAKE2b-256 | 22d2146fcde88751c12e335bb9337b864ffdc200a1a8a7540e20f35caee89a6c |
Hashes for jenkspy-0.4.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ec63404aa370b741b9bb5bdc3381600412fc3d66b724093e208d467f82207f4 |
|
MD5 | 499f9ac23426f33960e955893e62926b |
|
BLAKE2b-256 | 9864ae0d61fcc2e71a712f3256f5fa78afa42504f364b5afb5c7513737e35a59 |
Hashes for jenkspy-0.4.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f69c1f735c0e3cca7634771fd0d526c897f336c5e39ed9a0e36cae062714a58 |
|
MD5 | 701ce09db4c88c22cd3b3f6591405c9d |
|
BLAKE2b-256 | 9e648d729f30783be9bebd26f037e613ea23e28d06d3f7feaf389f3c6a7f46a0 |