Clustervis
Clustervis is a Python package for visualizing unsupervised clustering boundaries using surrogate classification models. It provides a visual representation of decision boundaries in the form of a dashboard or as an image.
Features
- Visualize decision boundaries with color-coded cluster regions.
- Visualize statistics such as the probabilities of the data points being in clusters.
- Save the plot in a path as an image (optional).
Installation
To install Clustervis you can use pip:
pip install clustervis
Usage
Dashboard
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
from clustervis import run_clustervis_dashboard
# Step 1: Generate synthetic data (ignoring ground-truth y to simulate unlabeled data)
X, _ = make_blobs(n_samples=400, centers=5, random_state=42, cluster_std=1.0)
# Step 2: Generate unsupervised cluster labels using KMeans
kmeans = KMeans(n_clusters=5, random_state=42)
cluster_labels = kmeans.fit_predict(X)
# Step 3: Declare custom user colors for the clusters
user_colors = [
[231, 76, 60],
[241, 196, 15],
[52, 152, 219],
[46, 204, 113],
[155, 89, 182]
]
# Step 4: Run the dashboard using the discovered clusters
run_clustervis_dashboard(X, cluster_labels, user_colors)
Ensemble classifier (Save enabled)
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
from sklearn.ensemble import BaggingClassifier
from sklearn.neighbors import KNeighborsClassifier
from clustervis import ensemble_classifier_plot
# Step 1: Generate synthetic data (ignoring ground-truth y to simulate real cluster data)
X, _ = make_blobs(n_samples=300, centers=4, random_state=76, cluster_std=1.0)
# Step 2a: Generate unsupervised cluster labels using KMeans
kmeans = KMeans(n_clusters=4, random_state=42)
cluster_labels = kmeans.fit_predict(X)
# Step 2b: Train the ensemble classifier to map the discovered cluster boundaries
base_estimator = KNeighborsClassifier(n_neighbors=3)
bagging_classifier = BaggingClassifier(
estimator=base_estimator, n_estimators=8, max_samples=0.05, random_state=1
)
bagging_classifier.fit(X, cluster_labels) # Fit to cluster_labels instead of y
# Step 3: Define some colors for each cluster
colors = [
(255, 0, 0),
(0, 255, 0),
(0, 0, 255),
(255, 255, 0)
] # Red, Green, Blue, Yellow
# Step 4: Declare the name, the resolution and the visibility of the plot
plotTitle = "RGB Clustering Decision Boundaries (Bagging Classifier)"
resolution = 100
show = True
# Step 5: Declare a path to save the plot
plotPath = "../images" # Example path
fileName = "ensembleClassifier.png"
# Step 6: Create a figure and a set of axes
fig, ax = plt.subplots()
# Step 7: Plot the decision boundary and save it
ensemble_classifier_plot(
X,
bagging_classifier,
colors,
resolution,
plotTitle,
show,
ax,
plotPath,
fileName
)
Base classifier (Save enabled)
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
from sklearn.neighbors import KNeighborsClassifier
from clustervis import base_classifier_plot
# Step 1: Generate synthetic data (ignoring ground-truth y to simulate real cluster data)
X, _ = make_blobs(n_samples=300, centers=4, random_state=76, cluster_std=1.0)
# Step 2a: Generate unsupervised cluster labels using KMeans
kmeans = KMeans(n_clusters=4, random_state=42)
cluster_labels = kmeans.fit_predict(X)
# Step 2b: Train a base classifier (e.g., a KNN Classifier) to map the discovered cluster boundaries
base_estimator = KNeighborsClassifier(n_neighbors=3)
base_estimator.fit(X, cluster_labels) # Fit to cluster_labels instead of y
# Step 3: Define some colors for each cluster (e.g., for 4 clusters)
colors = [
(255, 0, 0),
(0, 255, 0),
(0, 0, 255),
(255, 255, 0)
] # Red, Green, Blue, Yellow
# Step 4: Declare the name, the resolution and the visibility of the plot
plotTitle = "RGB Clustering Decision Boundaries (KNN Classifier)"
resolution = 100
show = True
# Step 5: Declare a path to save the plot
plotPath = "../images" # Example path
fileName = "baseClassifier.png"
# Step 6: Create a figure and an axes
fig, ax = plt.subplots()
# Step 7: Declare the percentage of points selected
percentageSelected = 1.0
# Step 8: Plot the decision boundary and save it
base_classifier_plot(
X,
base_estimator,
colors,
resolution,
plotTitle,
show,
ax,
percentageSelected,
plotPath,
fileName
)
License
This project is licensed under the MIT License.
Author
- Antonio De Angelis
- Email: deangelis.antonio122@gmail.com
- GitHub: https://github.com/AntonioDA2004/
Metadata
Release files for clustervis 1.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| clustervis-1.1.6.tar.gz | 7.5 kB | Without provenance | Details for clustervis-1.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| clustervis-1.1.6-py3-none-any.whl | Python 3 | none | any | Details for clustervis-1.1.6-py3-none-any.whl |
Total release size: 15.3 kB
Release files / clustervis-1.1.6.tar.gz
| Download URL | clustervis-1.1.6.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f06d1a25914d1424345afdd7553cadfccea0ad2087703352d3c41a507a8f7a3
|
|
BLAKE2b-256 checksum How to use checksums |
95f0c240939738fa597cb6be1154b7081a00cae9df6040d1683502ea4d426dc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / clustervis-1.1.6-py3-none-any.whl
| Download URL | clustervis-1.1.6-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2486f1163bbcbedec7bf33122604a7669ffe16c0642e0701c4e541ec721ecad
|
|
BLAKE2b-256 checksum How to use checksums |
bfa53891f39a21f0ea87711ebdf4f2c32546d3665749f5da8a8847cfcbf19f73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for clustervis 1.1.6
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.