Skip to main content

silhouetteclassifier

Unsupervised instance classification via an improved silhouette score, with an optional ensemble-metric refinement stage.

Instead of training on labels, SilhouetteClassifier ranks every instance by a weighted combination of local cohesion (closeness to nearest neighbors) and global separation (distance to the rest of the data), then partitions the ranked list according to the desired class ratios. This makes it useful for quick, label-light baselines on tabular data — including imbalanced binary problems — and for studying how internal geometry alone separates classes.

Import name is silclass (the distribution name on PyPI is silhouetteclassifier).

Installation

pip install silhouetteclassifier

For the benchmark comparison script (KMeans / UMAP / DBSCAN / MeanShift / OPTICS):

pip install "silhouetteclassifier[benchmark]"

Quick start

import pandas as pd
from silclass import SilhouetteClassifier

df = pd.read_csv("reduced.csv")
y = df["vital.status"]
X = df.drop(columns=["vital.status"])

clf = SilhouetteClassifier(n_neighbors=7)

# Supervised ratios: pass y so the class proportions are derived from labels
y_pred = clf.fit_predict(X, y=y)

# Or specify the major-class ratio directly (no labels needed)
# y_pred = clf.fit_predict(X, major_ratio=0.7, major_class=0)

print(clf.calculate_f1_scores(y))

Multi-class

y_pred = clf.fit_predict(
    X,
    class_ratios=[0.5, 0.3, 0.2],   # must sum to 1.0
    class_labels=[0, 1, 2],
)

Optional refinement

EnsembleRefinement takes initial binary labels and iteratively flips points to improve an ensemble of internal metrics (silhouette, Davies–Bouldin, Calinski–Harabasz, connectivity, density ratio). It is fully unsupervised; any true labels passed in are used only for reporting.

from silclass import EnsembleRefinement

initial = clf.fit_predict(X, y=y)
refiner = EnsembleRefinement(max_iterations=30, early_stopping=5)
refined = refiner.fit_refine(X, initial_labels=initial, y_true=y)  # y_true optional

API summary

SilhouetteClassifier(n_neighbors=15, scale_data=True)

  • fit_predict(X, y=None, major_ratio=0.5, major_class=0, class_ratios=None, class_labels=None) → labels
  • calculate_scores(X) → (cohesion, separation, silhouette)
  • calculate_f1_scores(true_labels) → dict with per-class F1, F1_major, F1_minor, accuracy
  • get_instance_data() / get_sorted_instances() → per-instance scores and labels

EnsembleRefinement(...)

  • fit_refine(X, initial_labels=None, y_true=None, major_ratio=0.5) → refined labels
  • get_history() → DataFrame of per-iteration metrics

License

MIT — see LICENSE.

Metadata

Release files for silhouetteclassifier 0.1.1

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

Source distribution (sdist)

Source distribution for silhouetteclassifier 0.1.1
File Size Uploaded Provenance
silhouetteclassifier-0.1.1.tar.gz 16.1 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 30.7 kB

Release files / silhouetteclassifier-0.1.1.tar.gz

Download URL silhouetteclassifier-0.1.1.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
136c548446e5e416f1e8a83548b37fe422329e31d81ccb6266cbd72a1ad1d965
BLAKE2b-256 checksum
How to use checksums
b707263ec1435509cf45f70b40e11b6db35c4aeb8d1b849be407763500cc9c06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / silhouetteclassifier-0.1.1-py3-none-any.whl

Download URL silhouetteclassifier-0.1.1-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a5011a88e6aaa0f3ea35754c77bcb6e4a1b31a134fef4724f183600d02b42cd
BLAKE2b-256 checksum
How to use checksums
dd4ee27e667dd0cfd9becbc8906e6aa66036d00d1cabdafd9c206f92e7e02775
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for silhouetteclassifier 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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