Skip to content
Back to skills

Clustering

ASecurity

"Guides pomegranate KMeans clustering workflows, including centroid

  • 247 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 8, 2026
developmentpythonrailsdebuggingapi

Works with

  • api

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add VectorSpaceLab/AREX-Skill --skill clustering --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Clustering?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Clustering
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectorspacelab-clustering/badge)](https://www.skillsdirectory.com/skills/vectorspacelab-clustering)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: clustering
description: "Guides pomegranate KMeans clustering workflows, including centroid
  initialization, fit/predict APIs, sample weights, initialization choices,
  convergence controls, and KMeans troubleshooting."
disable-model-invocation: true
metadata:
  disco-role: operating
license: MIT
---

# clustering

## Use this sub-skill when

Use this sub-skill for the pomegranate `KMeans` class as a standalone clusterer or as the initialization mechanism used by mixture and HMM workflows. It covers centroid initialization, `fit`, `predict`, `fit_predict`, sample weights, convergence controls, and common shape/initialization failures.

## Start here

Typical import:

```python
from pomegranate.kmeans import KMeans
```

Read [references/api-reference.md](references/api-reference.md) for constructor parameters, initialization options, and usage examples. Run [scripts/smoke_kmeans.py](scripts/smoke_kmeans.py) after installation for a tiny deterministic smoke check.

## Core workflow

1. **Choose `k` or explicit centroids.** Provide `k` to initialize from data or `centroids` to start from known centers.
2. **Use 2D numeric data.** KMeans expects `(n, d)` floating point features.
3. **Select initialization.** Start with `init='first-k'` for deterministic debugging or `init='random'` with `random_state` for randomized starts.
4. **Fit and predict.** Use `fit(X)`, `predict(X)`, or `fit_predict(X)` depending on whether you need cluster assignments immediately.
5. **Control convergence.** Use `max_iter`, `tol`, `inertia`, and `verbose` when diagnosing training behavior.

## Route elsewhere when

- KMeans is only an initializer inside `GeneralMixtureModel`: read [../mixtures-and-classifiers/SKILL.md](../mixtures-and-classifiers/SKILL.md) after checking the initialization choice here.
- KMeans initializes emissions inside HMM workflows: read [../sequence-models/SKILL.md](../sequence-models/SKILL.md).
- The task is probability scoring or sampling rather than clustering: use the relevant probabilistic model sub-skill.

## Guardrails

- `k` must be at least 2 when centroids are not provided.
- Component labels are arbitrary cluster ids; do not compare labels across independent fits without matching centroids.
- Submodular initialization options rely on `apricot-select`; use simpler initializers first when debugging.
- Read [references/troubleshooting.md](references/troubleshooting.md) when centroid shape, initialization, sample weights, masked data, or convergence is confusing.

Files in this skill

  • SKILL.md2.5 KB
  • references/api-reference.md2.4 KB
  • references/troubleshooting.md2 KB
  • scripts/smoke_kmeans.py729 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.