gap_statistic
App Listed Dormant
Dynamically get the suggested clusters in the data for unsupervised learning.
- Downloads
- 10
- Dependents
- Not applicable
- Stars
- 230
- Forks
- 50
- Contributors
- 6
- Commits
- 135
- Latest release
About
Python implementation of the Gap Statistic
Maintenance mode
I've lost interest/time in developing this further, other things have taken priority for some time now. However, all is not lost. I will be willing to review/comment on any issues/PRs but will not complete any fixes or feature requests myself.
Purpose
Dynamically identify the suggested number of clusters in a data-set using the gap statistic.
Full example available in a notebook HERE
Install:
Bleeding edge:
pip install git+git://github.com/milesgranger/gap_statistic.git
PyPi:
pip install --upgrade gap-stat
With Rust extension:
pip install --upgrade gap-stat[rust]
Uninstall:
pip uninstall gap-stat
Methodology:
This package provides several methods to assist in choosing the optimal number of clusters for a given dataset, based on the Gap method presented in "Estimating the number of clusters in a data set via the gap statistic" (Tibshirani et al.).
The methods implemented can cluster a given dataset using a range of provided k values, and provide you with statistics that can help in choosing the right number of clusters for your dataset. Three possible methods are:
Read the full README
- Taking the
kmaximizing the Gap value, which is calculated for eachk. This, however, might not always be possible, as for many datasets this value is monotonically increasing or decreasing. - Taking the smallest
ksuch that Gap(k) >= Gap(k+1) - s(k+1). This is the method suggested in Tibshirani et al. (consult the paper for details). The measurediff = Gap(k) - Gap(k+1) + s(k+1)is calculated for eachk; the parallel here, then, is to take the smallestkfor whichdiffis positive. Note that in some cases this can be true for the entire range ofk. - Taking the
kmaximizing the Gap* value, an alternative measure suggested in "A comparison of Gap statistic definitions with and with-out logarithm function" by Mohajer, Englmeier and Schmid. The authors claim this measure avoids the over-estimation of the number of clusters from which the original Gap statistics suffers, and can also suggest an optimal value for k for cases in which Gap cannot. They do warn, however, that the original Gap statistic performs better than Gap* in the case of overlapped clusters, due to its tendency to overestimate the number of clusters.
Note that none of the above methods is guaranteed to find an optimal value for k, and that they often contradict one another. Rather, they can provide more information on which to base your choice of k, which should take numerous other factors into account.
Use:
First, construct an OptimalK object. Optional intialization parameters are:
n_jobs- Splits computation into this number of parallel jobs. Requires choosing a parallel backend.parallel_backend- Possible values arejoblib,rustormultiprocessingfor the built-in Python backend. Ifparallel_backend == 'rust'it will use all cores.clusterer- Takes a custom clusterer function to be used when clustering. See the example notebook for more details.clusterer_kwargs- Any keyword arguments to be forwarded to the custom clusterer function on each call.
An example intialization:
optimalK = OptimalK(n_jobs=4, parallel_backend='joblib')
After the object is created, it can be called like a function, and provided with a dataset for which the optimal K is found and returned. Parameters are:
X- A pandas dataframe or numpy array of data points of shape(n_samples, n_features).n_refs- The number of random reference data sets to use as inertia reference to actual data. Optional.cluster_array- A 1-dimensional iterable of integers; each representingn_clustersto try on the data. Optional.
For example:
import numpy as np
n_clusters = optimalK(X, cluster_array=np.arange(1, 15))
After performing the search procedure, a DataFrame of gap values and other usefull statistics for each passed cluster count is now available as the gap_df attributre of the OptimalK object:
optimalK.gap_df.head()
The columns of the dataframe are:
n_clusters- The number of clusters for which the statistics in this row were calculated.gap_value- The Gap value for thisn.gap*- The Gap* value for thisn.ref_dispersion_std- The standard deviation of the reference distributions for thisn.sk- The standard error of the Gap statistic for thisn.sk*- The standard error of the Gap* statistic for thisn.diff- The diff value for thisn(see the methodology section for details).diff*- The diff* value for thisn(corresponding to the diff value for Gap*).
Additionally, the relation between the above measures and the number of clusters can be plotted by calling the OptimalK.plot_results() method (meant to be used inside a Jupyter Notebook or a similar IPython-based notebook), which prints four plots:
- A plot of the Gap value versus n, the number of clusters.
- A plot of diff versus n.
- A plot of the Gap* value versus n, the number of clusters.
- A plot of the diff* value versus n.
Compatibility
- License
- Unlicense
- Crate facts
- Not measured
- Runs on, Native code and Python bindings read crates on crates.io. This entry lists no crate.
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
Dynamically get the suggested clusters in the data for unsupervised learning. |
10 binary downloads per release | Not applicable | 230 | Not measured | Not measured | Unlicense | |
|
linfa Featured
A Machine Learning framework for Rust |
177,963 downloads over 30 days | 60 | 4,770 | 0.8.1 | GPU support unknown | Binds native code: lapack-sys (feature intel-mkl-static) | Apache-2.0 OR MIT |
|
A Rust implementation of the Leiden algorithm for community detection in large networks. |
1,765 downloads over 30 days | 1 | 1 | 0.1.0 | GPU support unknown | No native code found | MIT |
|
Rust bindings for the liblinear C++ library |
922 downloads over 30 days | 1 | 10 | 1.0.0 | GPU support unknown | Binds native code: liblinear.a. Build uses a native toolchain: cc | MIT |
|
A machine learning package for Rust. |
578 downloads over 30 days | 2 | 647 | 0.5.0 | GPU support unknown | Binds native code: libsvm | Apache-2.0 |
|
rust-automl Listed
Automated machine learning for classification and regression |
170 downloads over 30 days | 1 | 39 | 0.3.1 | GPU support unknown | No native code found | Apache-2.0 OR MIT |
|
treeboost Listed
Gradient-boosted decision trees for tabular data: trains a baseline model in one call, with full control over boosting modes and configs, and Scalar, AVX-512, SVE2, WGPU and CUDA backends. Python bindings |
18 downloads over 30 days | 0 | 9 | 0.1.2 | CUDA, WebGPU | No native code found | Apache-2.0 |
Why ListedNo archive, New or Featured rule places it, so it is Listed.
What it lacks for Featured
- The project is dormant and not finished. Dormancy rule
What else the check found
- The last activity is on 31 Jul 2023, 1197 days ago. That reaches the 365 days the rules expect, so the project is dormant. Dormancy rule
- The oldest outside issue waits 902 days for a reply, past the limit of 270. No maintainer replied in 365 days. Rot signals rule
Not measured: Unpatched vulnerabilities past the grace window, First release.
Exact rules: Listed, Featured app. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: app: E = 365 daysdormancy: last activity 2023-07-31, 1197 days ago, E = 365: dormantrot: oldest unanswered issue 902 days (limit 270), no maintainer reply in 365 daysfeatured: not featured: dormant and not stablelisted: listed: no archive, new or featured rule applies
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources4 sources
- Description: the GitHub repository description
- GitHub releases, fetched
- GitHub repository, fetched
- GitHub contributors, fetched
Adoption10 binary downloads per release4 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | Not measured | Yes | ||
| New dependents (365 days) | Not measured | Yes | ||
| Peak active dependents | Not measured | Yes | ||
| Active dependents as a share of the peak | Not measured | Yes | ||
| Binary downloads per release | 10 | GitHub releases | Yes |
MaintenanceLatest human commit: 3 years ago7 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2023-07-31 | GitHub repository | Yes | |
| Latest release | 2023-07-31 | GitHub releases | Yes | |
| First release | Not measured | Yes | ||
| Latest version | Not measured | Yes | ||
| Days the oldest outside issue waits for a reply | 902 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 0 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | Not measured | Yes | ||
| Published docs | Not measured | Yes | ||
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityNot measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | Not measured | Yes | ||
| RustSec unmaintained advisory | Not measured | Yes | ||
| Deprecation notice | Not measured | Yes | ||
| Deprecated requirement | Not measured | Yes |
Distribution31 binary downloads over the last 3 releases10 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | Not measured | Yes | ||
| Downloads over 30 days | Not measured | Yes | ||
| Binary downloads over the last 3 releases | 31 | GitHub releases | Yes | |
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | Not measured | Yes | ||
| Every version 0.0.x | Not measured | Yes | ||
| Every version yanked | Not measured | Yes | ||
| Crate deleted from crates.io | Not measured | Yes |
Repository230 stars, 50 forks, 6 contributors, 135 commits. Stars alone never qualify a project.1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 230 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 50 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 6 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 135 | GitHub repository | No | |
| Repository's main crate left out of the entry | Not measured | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | Unlicense | GitHub repository | No | |
| Runs on, from listed crates and their direct dependencies | Not measured | No | ||
| What shows each backend | Not measured | No | ||
| Native code, from listed crates and their dependencies | Not measured | No | ||
| Python bindings, from direct dependencies of listed crates | Not measured | No | ||
| Crates that depend on a listed crate directly | Not measured | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.