gap_statistic

App Listed Dormant

Dynamically get the suggested clusters in the data for unsupervised learning.

Checked · Sources

Downloads
10
Dependents
Not applicable
Stars
230
Forks
50
Contributors
6
Commits
135
Latest release

About

From the project README ·

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 k maximizing the Gap value, which is calculated for each k. This, however, might not always be possible, as for many datasets this value is monotonically increasing or decreasing.
  • Taking the smallest k such that Gap(k) >= Gap(k+1) - s(k+1). This is the method suggested in Tibshirani et al. (consult the paper for details). The measure diff = Gap(k) - Gap(k+1) + s(k+1) is calculated for each k; the parallel here, then, is to take the smallest k for which diff is positive. Note that in some cases this can be true for the entire range of k.
  • Taking the k maximizing 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 are joblib, rust or multiprocessing for the built-in Python backend. If parallel_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 representing n_clusters to 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 this n.
  • gap* - The Gap* value for this n.
  • ref_dispersion_std - The standard deviation of the reference distributions for this n.
  • sk - The standard error of the Gap statistic for this n.
  • sk* - The standard error of the Gap* statistic for this n.
  • diff - The diff value for this n (see the methodology section for details).
  • diff* - The diff* value for this n (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.

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.

gap_statistic beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
gap_statistic This page App Listed Dormant

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
fa-leiden-cd Listed Dormant

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
liblinear-rs Listed Dormant

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
rustlearn Listed Dormant

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

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

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 days
  • dormancy: last activity 2023-07-31, 1197 days ago, E = 365: dormant
  • rot: oldest unanswered issue 902 days (limit 270), no maintainer reply in 365 days
  • featured: not featured: dormant and not stable
  • listed: 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
Adoption10 binary downloads per release4 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependentsNot measuredYes
New dependents (365 days)Not measuredYes
Peak active dependentsNot measuredYes
Active dependents as a share of the peakNot measuredYes
Binary downloads per release10GitHub releasesYes
MaintenanceLatest human commit: 3 years ago7 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2023-07-31GitHub repositoryYes
Latest release2023-07-31GitHub releasesYes
First releaseNot measuredYes
Latest versionNot measuredYes
Days the oldest outside issue waits for a reply902GitHub repositoryYes
Maintainer replies over 365 days0GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repoNot measuredYes
Published docsNot measuredYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityNot measured
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windowNot measuredYes
RustSec unmaintained advisoryNot measuredYes
Deprecation noticeNot measuredYes
Deprecated requirementNot measuredYes
Distribution31 binary downloads over the last 3 releases10 not measured
Distribution measurements
SignalValueSourceFetchedCounts
ReleasesNot measuredYes
Downloads over 30 daysNot measuredYes
Binary downloads over the last 3 releases31GitHub releasesYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleaseNot measuredYes
Every version 0.0.xNot measuredYes
Every version yankedNot measuredYes
Crate deleted from crates.ioNot measuredYes
Repository230 stars, 50 forks, 6 contributors, 135 commits. Stars alone never qualify a project.1 not measured
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars230GitHub repositoryYes — one part of the repository route
GitHub forks50GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account6GitHub contributorsYes — one part of the repository route
Commits on the default branch135GitHub repositoryNo
Repository's main crate left out of the entryNot measuredYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseUnlicenseGitHub repositoryNo
Runs on, from listed crates and their direct dependenciesNot measuredNo
What shows each backendNot measuredNo
Native code, from listed crates and their dependenciesNot measuredNo
Python bindings, from direct dependencies of listed cratesNot measuredNo
Crates that depend on a listed crate directlyNot measuredNo

Corrections and review history

Report a correction

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.