A Python package for clustering visualization
Project description
Clustervis
Clustervis is a Python package for visualizing clustering results from a classifier. 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.datasets import make_blobs
from clustervis import run_clustervis_dashboard
import numpy as np
# Step 1: Generate synthetic data
X, y = make_blobs(n_samples=400, centers=5, random_state=42, cluster_std=1.0)
# Step 2: Declare custom user colors for the clusters
user_colors = np.array([
[231, 76, 60], [241, 196, 15], [52, 152, 219], [46, 204, 113], [155, 89, 182]
])
# Step 3: Run the dashboard (you can optionally use a custom preprocessor and model)
run_clustervis_dashboard(X, y, user_colors)
Ensemble classifier (Save enabled)
from clustervis import ensemble_classifier_plot
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.ensemble import BaggingClassifier
from sklearn.neighbors import KNeighborsClassifier
# Step 1: Generate synthetic data
X, y = make_blobs(n_samples=300, centers=4, random_state=76, cluster_std=1.0)
# Step 2: Train an ensemble classifier (e.g., a Bagging Classifier)
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, y)
# Step 3: Define some colors for each class (e.g., for 4 classes)
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 = "/data/notebook_files" # Example path for JetBrains Datalore
fileName = "classifier.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 disabled)
from clustervis import base_classifier_plot
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.neighbors import KNeighborsClassifier
# Step 1: Generate synthetic data
X, y = make_blobs(n_samples=300, centers=4, random_state=76, cluster_std=1.0)
# Step 2: Train a base classifier (e.g., a KNN Classifier)
base_estimator = KNeighborsClassifier(n_neighbors=3)
base_estimator.fit(X, y)
# Step 3: Define some colors for each class (e.g., for 4 classes)
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: Create a figure and an axes
fig, ax = plt.subplots()
# Step 6: Declare the percentage of points selected
percentageSelected = 1.0
# Step 7: Plot the decision boundary
base_classifier_plot(X, base_estimator, colors, resolution, plotTitle, show, ax, percentageSelected)
License
This project is licensed under the MIT License.
Author
- Antonio De Angelis
- Email: deangelis.antonio122@gmail.com
- GitHub: https://github.com/AntonioDA2004/
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clustervis-1.1.2.tar.gz.
File metadata
- Download URL: clustervis-1.1.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88039eb44e98fc5e2b9c8efa4fd0075615799ad189a4b65dca577fb1a45c3d01
|
|
| MD5 |
e9995e064ff6d77f67c0f17f6613f8e7
|
|
| BLAKE2b-256 |
fec9632e9e774ac48173c1bca3578be093c80a4743df8d38ab357180f7e7ee83
|
File details
Details for the file clustervis-1.1.2-py3-none-any.whl.
File metadata
- Download URL: clustervis-1.1.2-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a6517b614ea2fc687cb5f29350f58742970ea1e82e6c7142848d5c149304865
|
|
| MD5 |
f2f484f9d38bfb88406f6878ba5a2bca
|
|
| BLAKE2b-256 |
d1ee78ee73c567ee543454b475b29d7283a1f93b2ff7977fef446fd9048736eb
|