Skip to main content

A Python package for clustering visualization

Project description

Clustervis

Clustervis is a Python package for visualizing clustering results. 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 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

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.52.tar.gz (5.3 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.52-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for clustervis-1.0.52.tar.gz
Algorithm Hash digest
SHA256 e3901b4e9628dfdd6ab7c8804cc7f032b606ac4c9f6facd82bf218a4d10f5953
MD5 66dc3efb9806cb8bfa833b7917b17c1b
BLAKE2b-256 686a45a1d9bcecbc02772e289ecc0971bdd4bf43b73c4e4b954fdfe8c292ac7d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clustervis-1.0.52-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.9.13

File hashes

Hashes for clustervis-1.0.52-py3-none-any.whl
Algorithm Hash digest
SHA256 9522320dc6782f6fe01f2843b3f3a9eb0b6ded4fdc45e363226f9b08a9a04dc4
MD5 0edd97ef1777538fe64a4790d9006a4f
BLAKE2b-256 2b08a94468163d586c9b0c909e6423acb1ea06191969f59372120723db05cda8

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