{"id":13473263,"url":"https://github.com/mthh/jenkspy","last_synced_at":"2025-05-15T08:09:19.395Z","repository":{"id":41754468,"uuid":"68095675","full_name":"mthh/jenkspy","owner":"mthh","description":"Compute Natural Breaks in Python (Fisher-Jenks algorithm)","archived":false,"fork":false,"pushed_at":"2025-02-14T15:15:41.000Z","size":215,"stargazers_count":224,"open_issues_count":3,"forks_count":28,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-14T12:18:05.088Z","etag":null,"topics":["data-classification","jenks-fisher","python-library"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/jenkspy","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mthh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-13T09:46:04.000Z","updated_at":"2025-04-04T11:58:06.000Z","dependencies_parsed_at":"2023-01-28T20:45:24.978Z","dependency_job_id":"8651b758-0db8-4a0a-a939-2f8e514b194d","html_url":"https://github.com/mthh/jenkspy","commit_stats":{"total_commits":88,"total_committers":8,"mean_commits":11.0,"dds":"0.48863636363636365","last_synced_commit":"20da64dc377d185e1604c2324bd7e75d7b6e1cdd"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthh%2Fjenkspy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthh%2Fjenkspy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthh%2Fjenkspy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mthh%2Fjenkspy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mthh","download_url":"https://codeload.github.com/mthh/jenkspy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877967,"owners_count":21176244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-classification","jenks-fisher","python-library"],"created_at":"2024-07-31T16:01:02.198Z","updated_at":"2025-04-14T12:18:15.388Z","avatar_url":"https://github.com/mthh.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Jenkspy: Fast Fisher-Jenks breaks for Python\n\nCompute \"natural breaks\" (*Fisher-Jenks algorithm*) on list / tuple / array / numpy.ndarray of integers/floats.\n\nThe 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.\n\nIntended compatibility: CPython 3.7+\n\nWheels are provided via PyPI for Windows / MacOS / Linux users - Also available on conda-forge channel for Anaconda users.\n\n[![](https://github.com/mthh/jenkspy/actions/workflows/wheel.yml/badge.svg)](https://github.com/mthh/jenkspy/actions/workflows/wheel.yml)\n[![](https://img.shields.io/pypi/v/jenkspy.svg?color=007ec6)](https://pypi.python.org/pypi/jenkspy)\n[![](https://anaconda.org/conda-forge/jenkspy/badges/version.svg)](https://anaconda.org/conda-forge/jenkspy)\n[![](https://img.shields.io/pypi/dm/jenkspy.svg)](https://pypi.python.org/pypi/jenkspy)\n\n## Usage\n\nTwo ways of using `jenkspy` are available:\n\n- by using the `jenks_breaks` function which takes as input\na [`list`](https://docs.python.org/3/library/stdtypes.html#list)\n/ [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple)\n/ [`array.array`](https://docs.python.org/3/library/array.html#array.array)\n/ [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html) 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).\n\n```python\n\u003e\u003e\u003e import jenkspy\n\u003e\u003e\u003e import json\n\n\u003e\u003e\u003e with open('tests/test.json', 'r') as f:\n...     # Read some data from a JSON file\n...     data = json.loads(f.read())\n...\n\u003e\u003e\u003e jenkspy.jenks_breaks(data, n_classes=5) # Asking for 5 classes\n[0.0028109620325267315, 2.0935479691252112, 4.205495140049607, 6.178148351609707, 8.09175917180255, 9.997982932254672]\n# ^                      ^                    ^                 ^                  ^                 ^\n# Lower bound            Upper bound          Upper bound       Upper bound        Upper bound       Upper bound\n# 1st class              1st class            2nd class         3rd class          4th class         5th class\n# (Minimum value)                                                                                    (Maximum value)\n```\n\n- by using the `JenksNaturalBreaks` class that is inspired by `scikit-learn` classes.\n\nThe `.fit` and `.group` behavior is slightly different from `jenks_breaks`,\nby accepting value outside the range of the minimum and maximum value of `breaks_`,\nretaining the input size. It means that fit and group will use only the `inner_breaks_`.\nAll 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.\n\n```python\n\u003e\u003e\u003e from jenkspy import JenksNaturalBreaks\n\n\u003e\u003e\u003e x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n\n\u003e\u003e\u003e jnb = JenksNaturalBreaks(4) # Asking for 4 clusters\n\n\u003e\u003e\u003e jnb.fit(x) # Create the clusters according to values in 'x'\n\u003e\u003e\u003e print(jnb.labels_) # Labels for fitted data\n... print(jnb.groups_) # Content of each group\n... print(jnb.breaks_) # Break values (including min and max)\n... print(jnb.inner_breaks_) # Inner breaks (ie breaks_[1:-1])\n[0 0 0 1 1 1 2 2 2 3 3 3]\n[array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8]), array([ 9, 10, 11])]\n[0.0, 2.0, 5.0, 8.0, 11.0]\n[2.0, 5.0, 8.0]\n\n\u003e\u003e\u003e print(jnb.predict(15)) # Predict the group of a value\n3\n\n\u003e\u003e\u003e print(jnb.predict([2.5, 3.5, 6.5])) # Predict the group of several values\n[1 1 2]\n\n\u003e\u003e\u003e print(jnb.group([2.5, 3.5, 6.5])) # Group the elements into there groups\n[array([], dtype=float64), array([2.5, 3.5]), array([6.5]), array([], dtype=float64)]\n```\n\n## Installation\n\n- **From pypi**\n\n```shell\npip install jenkspy\n```\n\n- **From source**\n\n```shell\ngit clone http://github.com/mthh/jenkspy\ncd jenkspy/\npip install .\n```\n\n- **For anaconda users**\n\n```shell\nconda install -c conda-forge jenkspy\n```\n\n## Requirements\n\n- [Numpy](https://numpy.org)\n\n-  Only for building from source: C compiler, Python C headers, setuptools and Cython.\n\n\n## Motivation:\n\n-  Making a painless installing C extension so it could be used more easily\n   as a dependency in an other package (and so learning how to build wheels\n   using *appveyor* / *travis* at first - now it uses *GitHub Actions*).\n-  Getting the break values! (and fast!). No fancy functionality provided,\n   but contributions/forks/etc are welcome.\n-  Other python implementations are currently existing but not as fast or not available on PyPi.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmthh%2Fjenkspy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmthh%2Fjenkspy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmthh%2Fjenkspy/lists"}