Skip to main content

Clustering Utilities

This packages provides a simple convenience wrapper around some basic sklearn utilities for clustering. The only function available is eval_clustering().

Installation

pip install clustutils4r

Available Parameters

model: Clustering model object (untrained)

X: Numpy array containing preprocessed, normalized, complete dataset features

gt_labels: Numpy array containing encoded ground-truth labels for X (often not available)

num_runs: No. of times to fit a model

best_model_metric: Metric to use to choose the best model

make_silhoutte_plots: Whether to make silhouette plots for the best model (default = False).

embed_data_in_2d: Whether to compute TSNE embeddings of the X to plotted alongside silhouette plot or plot the first 2 features (default = False).

save_dir: location to store results; directory will be created if it does not exist

save: set True if you want to save all results in save_dir; defaults to False

show: display all results; useful in notebooks; defaults to False

Example Usage

import os
import numpy as np
from sklearn.datasets import make_blobs, load_iris, load_digits
from eval_clustering import eval_clustering

## For testing purposes
rng = np.random.RandomState(0)
n_samples=1000
X, y = make_blobs(n_samples=n_samples, centers=5, n_features=2, cluster_std=0.60, random_state=rng)

save_dir = "results"
os.makedirs(save_dir, exist_ok=True)

best_model, grid_search_results = eval_clustering(
                                       X=X,                                               # dataset to cluster
                                       gt_labels=y,                                       # ground-truth labels; often these aren't available so don't pass this argument
                                       num_runs=10,                                       # number of times to fit a model
                                       best_model_metric="FMI",                           # metric to use to choose the best model
                                       make_silhoutte_plots=True, embed_data_in_2d=False, # whether to make silhouette plots
                                       show=False,                                        # whether to display the plots; this is used in a notebook
                                       save=True, save_dir="results"                      # whether to save the plots
                                    )

grid_search_results sil

Metadata

Release files for clustutils4r 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clustutils4r 1.0.2
File Size Uploaded Provenance Actions
clustutils4r-1.0.2.tar.gz 22.4 kB Without provenance Details for clustutils4r-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clustutils4r 1.0.2
File Interpreter ABI Platform Actions
clustutils4r-1.0.2-py3-none-any.whl Python 3 none any Details for clustutils4r-1.0.2-py3-none-any.whl

Total release size: 43.9 kB

Release files / clustutils4r-1.0.2.tar.gz

Download URL clustutils4r-1.0.2.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0465bae02572fcebf1cbb432e25a89daf04d017ec53d9f4b88a06755f2262411
BLAKE2b-256 checksum
How to use checksums
6cba2e13ad6fd2b6afbb1735196d61469be29e02f766235e3d023dbc3679d058
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.14

Release files / clustutils4r-1.0.2-py3-none-any.whl

Download URL clustutils4r-1.0.2-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99d5ba5dd79a5b70426ba0ba3bd3f4c2bf1b8a3f8eb6f428cc86d8a4b4a5dc6d
BLAKE2b-256 checksum
How to use checksums
2cfa9127fece987ead98b572ce825c2bf9bd9c80a8ca624588f74699f95696a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.14

Security for clustutils4r 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page