Skip to main content

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.

Features

  • Visualize decision boundaries with color-coded cluster regions.
  • Save the plot in a path as an image (optional).

Installation

To install Clustervis you can use pip:

pip install clustervis

Usage

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 7: Create a figure and an axes
fig, ax = plt.subplots()

# Step 8: 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

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

clustervis-1.0.51.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clustervis-1.0.51-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file clustervis-1.0.51.tar.gz.

File metadata

  • Download URL: clustervis-1.0.51.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for clustervis-1.0.51.tar.gz
Algorithm Hash digest
SHA256 ba2c24d56cd3f8bafc8576fad44e82367ef08b0b2a337a58e3a1717867ff8947
MD5 38fa7bc069fa17ff2500e9ac0f935422
BLAKE2b-256 95577a4466865dd3895c73e76799e50131bcfc694f526fdc22c9867cfe757090

See more details on using hashes here.

File details

Details for the file clustervis-1.0.51-py3-none-any.whl.

File metadata

  • Download URL: clustervis-1.0.51-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for clustervis-1.0.51-py3-none-any.whl
Algorithm Hash digest
SHA256 5b076c1114c6d2c8240625b506f6714faa11e9b719454a4f083998b5207dba2b
MD5 34cdc2dfc6f6174b565cd7e25af994b2
BLAKE2b-256 089a4982286e242570d1249d3e8c0abd1a02c889e06a7a47bb23d318397ea17d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page