https://github.com/ap6yc/cvi

A Python package implementing both batch and incremental cluster validity indices.

https://github.com/ap6yc/cvi

Science Score: 33.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    1 of 1 committers (100.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.0%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

A Python package implementing both batch and incremental cluster validity indices.

Basic Info
  • Host: GitHub
  • Owner: AP6YC
  • License: mit
  • Language: Python
  • Default Branch: develop
  • Size: 1.38 MB
Statistics
  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • Open Issues: 8
  • Releases: 12
Created almost 4 years ago · Last pushed about 2 years ago
Metadata Files
Readme License Code of conduct

README.md

cvi-header

A Python package implementing both batch and incremental cluster validity indices (CVIs).

| Stable Docs | Dev Docs | Build Status | Coverage | |:----------------:|:------------:|:----------------:|:------------:| | Stable | Dev| Build Status | Codecov | | Version | Issues | Downloads | Zenodo DOI | | version | issues | Downloads | DOI |

Table of Contents

Cluster Validity Indices

Say you have a clustering algorithm that clusters a set of samples containing features of some kind and some dimensionality. Great! That was a lot of work, and you should feel accomplished. But how do you know that the algorithm performed well? By definition, you wouldn't have the true label belonging to each sample (if one could even exist in your context), just the label prescribed by your clustering algorithm.

Enter Cluster Validity Indices (CVIs).

CVIs are metrics of cluster partitioning when true cluster labels are unavailable. Each operates on only the information available (i.e., the provided samples of features and the labels prescribed by the clustering algorithm) and produces a metric, a number that goes up or down according to how well the CVI believes the clustering algorithm appears to, well, cluster. Clustering well in this context means correctly partitioning (i.e., separating) the data rather than prescribing too many different clusters (over partitioning) or too few (under partitioning). Every CVI itself also behaves differently in terms of the range and scale of their numbers. Furthermore, each CVI has an original batch implementation and incremental implementation that are equivalent.

The cvi Python package contains a variety of these batch and incremental CVIs.

Installation

The cvi package is listed on PyPI, so you may install the latest version with

python pip install cvi

You can also specify a version to install in the usual way with

python pip install cvi==v0.6.0

Alternatively, you can manually install a release from the releases page on GitHub.

Usage

Quickstart

Create a CVI object and compute the criterion value in batch with get_cvi:

```python

Import the library

import cvi

Create a Calinski-Harabasz (CH) CVI object

my_cvi = cvi.CH()

Load some data from some clustering algorithm

samples, labels = loadsomeclustering_data()

Compute the final criterion value in batch

criterionvalue = mycvi.get_cvi(samples, labels) ```

or do it incrementally, also with get_cvi:

```python

Datasets are numpy arrays

import numpy as np

Create a container for criterion values

nsamples = len(labels) criterionvalues = np.zeros(n_samples)

Iterate over the data

for ix in range(nsamples): criterionvalues = mycvi.getcvi(samples[ix, :], labels[ix]) ```

Detailed Usage

The cvi package contains a set of implemented CVIs with batch and incremental update methods. Each CVI is a standalone stateful object inheriting from a base class CVI, and all CVI functions are object methods, such as those that update parameters and return the criterion value.

Instantiate a CVI of you choice with the default constructor:

```python

Import the package

import cvi

Import numpy for some data handling

import numpy as np

Instantiate a Calinski-Harabasz (CH) CVI object

my_cvi = cvi.CH() ```

CVIs are instantiated with their acronyms, with a list of all implemented CVIS being found in the Implemented CVIs section.

A batch of data is assumed to be a numpy array of samples and a numpy vector of integer labels.

```python

Load some data

samples, labels = myclusteringalg(some_data) ```

NOTE:

The cvi package assumes the Numpy row-major convention where rows are individual samples and columns are features. A batch dataset is then [n_samples, n_features] large, and their corresponding labels are [n_samples] large.

You may compute the final criterion value with a batch update all at once with CVI.get_cvi

```python

Get the final criterion value in batch mode

criterionvalue = mycvi.get_cvi(samples, labels) ```

or you may get them incrementally with the same method, where you pass instead just a single numpy vector of features and a single integer label. The incremental methods are used automatically based upon the dimensions of the data that is passed.

```python

Create a container for the criterion value after each sample

nsamples = len(labels) criterionvalues = np.zeros(n_samples)

Iterate across the data and store the criterion value over time

for ix in range(nsamples): sample = samples[ix, :] label = labels[ix] criterionvalues[ix] = mycvi.getcvi(sample, label) ```

NOTE:

Currently only using either batch or incremental methods is supported; switching from batch to incremental updates with the same is not yet implemented.

Implemented CVIs

The following CVIs have been implemented as of the latest version of cvi:

  • CH: Calinski-Harabasz
  • cSIL: Centroid-based Silhouette
  • DB: Davies-Bouldin
  • GD43: Generalized Dunn's Index 43.
  • GD53: Generalized Dunn's Index 53.
  • PS: Partition Separation.
  • rCIP: (Renyi's) representative Cross Information Potential.
  • WB: WB-index.
  • XB: Xie-Beni.

History

  • 8/18/2022: Initialize project.
  • 9/8/2022: First release on PyPi and initiate GitFlow.
  • 8/10/2023: v0.5.1 released.
  • 5/31/2024: Updated documentation.

Acknowledgements

Derivation

The incremental and batch CVI implementations in this package are largely derived from the following Julia language implementations by the same authors of this package:

Authors

The principal authors of the cvi pacakge are:

Related Projects

If this package is missing something that you need, feel free to check out some related Python cluster validity packages:

Assets

Fonts

The following font is used in the logo:

Icons

The icon for the project is taken from:

Owner

  • Name: Sasha Petrenko
  • Login: AP6YC
  • Kind: user

Graduate researcher of applied computational intelligence at the Missouri University of Science and Technology.

GitHub Events

Total
Last Year

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 213
  • Total Committers: 1
  • Avg Commits per committer: 213.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 23
  • Committers: 1
  • Avg Commits per committer: 23.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Sasha Petrenko s****5@u****u 213
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 41
  • Total pull requests: 43
  • Average time to close issues: 17 days
  • Average time to close pull requests: about 9 hours
  • Total issue authors: 2
  • Total pull request authors: 1
  • Average comments per issue: 0.39
  • Average comments per pull request: 0.56
  • Merged pull requests: 43
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • AP6YC (35)
  • NiklasMelton (6)
Pull Request Authors
  • AP6YC (46)
Top Labels
Issue Labels
enhancement (29) documentation (11) bug (4) tests (2) invalid (1)
Pull Request Labels
enhancement (26) documentation (10) release (10) bug (2)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 78 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 13
  • Total maintainers: 1
pypi.org: cvi

A Python package for both batch and incremental cluster validity indices.

  • Homepage: https://github.com/AP6YC/cvi
  • Documentation: https://cluster-validity-indices.readthedocs.io/
  • License: MIT License Copyright (c) 2022 Sasha Petrenko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • Latest release: 0.6.0
    published about 2 years ago
  • Versions: 13
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 78 Last month
Rankings
Dependent packages count: 6.6%
Downloads: 20.8%
Average: 23.4%
Stargazers count: 28.2%
Forks count: 30.5%
Dependent repos count: 30.6%
Maintainers (1)
Last synced: 11 months ago

Dependencies

.github/workflows/Publish.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • pypa/gh-action-pypi-publish v1.5.1 composite
.github/workflows/Test.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • codecov/codecov-action v3 composite
dev-requirements.txt pypi
  • build * development
  • flake8 * development
  • jupyterlab * development
  • numpy * development
  • pandas * development
  • pytest * development
  • scikit-learn * development
  • setuptools * development
  • sphinx * development
  • sphinx-rtd-theme * development
  • tqdm * development
  • twine * development
docs/requirements.txt pypi
  • sphinx *
  • sphinx-rtd-theme *
requirements.txt pypi
  • coverage *
  • pandas *
  • pytest-cov *
  • scikit-learn *
  • tqdm *
.github/workflows/Documentation.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • peaceiris/actions-gh-pages v3 composite
pyproject.toml pypi
setup.py pypi