cluster-model-selection
Use Yellowbrick clustering diagnostics and model-selection visualizers for k selection, validation curves, cross-validation scores, RFECV, feature importances, and dropping curves.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- cluster-model-selection
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use Yellowbrick clustering diagnostics and model-selection visualizers for k selection, validation curves, cross-validation scores, RFECV, feature importances, and dropping curves.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md10.5 KB
- 参考文档references/troubleshooting.md9.1 KB
- 参考文档references/workflows.md8.9 KB
- 脚本scripts/model_selection_smoke.py15.9 KB
03 SKILL.md 正文
Yellowbrick Cluster and Model Selection Visualizers
Use this sub-skill when the user needs Yellowbrick visual diagnostics for unsupervised clustering or for scikit-learn model-selection workflows that train many estimator clones. It covers:
- clustering diagnostics:
KElbowVisualizer,SilhouetteVisualizer,InterclusterDistance, andkelbow_visualizer/silhouette_visualizer/intercluster_distancequick methods; - cross-validation and hyperparameter diagnostics:
ValidationCurve,LearningCurve, andCVScores; - feature selection and feature-rank diagnostics:
RFECV,FeatureImportances, andDroppingCurve.
Route elsewhere when
- The request is for classifier score plots such as confusion matrices, ROC/PR curves, class prediction error, classification reports, or discrimination thresholds: route to classifier visualizers.
- The request is for regressor score plots such as residuals, prediction error, Cook's distance, or alpha selection: route to regressor visualizers.
- The request is for dataset download/cache/loaders or text visualizers: route to
../text-and-datasets/SKILL.mdwhen that sub-skill is available. - The request is mainly about Matplotlib backend,
show(outpath=...), axes reuse, Yellowbrick style, or shared lifecycle mechanics: read root visualizer patterns first, then return here for cluster/model-selection choices. - The failure is a broad installation, backend, font, display, or scikit-learn compatibility issue: read root troubleshooting, then this sub-skill's troubleshooting.
Fast routing
| User goal | Use | Key requirements |
|---|---|---|
Pick a candidate number of clusters k |
KElbowVisualizer |
Centroid-style clusterer with n_clusters, fit, and labels_; tune k, metric, timings, and locate_elbow. |
Compare cluster density and imbalance for one k |
SilhouetteVisualizer |
Clusterer with fit_predict or fit+predict; at least two non-empty clusters. |
| Show relative cluster-center distances | InterclusterDistance |
Clusterer with cluster_centers_ and labels_; embedding is "mds" or "tsne"; scoring is currently "membership". |
| Tune one estimator hyperparameter | ValidationCurve |
Exact param_name, 1-D param_range, explicit cv, valid scoring, bounded n_jobs. |
| Ask whether more data helps | LearningCurve |
Bounded train_sizes, explicit cv, valid scoring; works with classifiers, regressors, and some clusterers. |
| Show fold-to-fold score spread | CVScores |
Estimator plus cv strategy and scoring; displays per-fold bars and mean line. |
| Choose number of features with recursive elimination | RFECV |
Estimator must expose coef_ or feature_importances_ after fit; step must be positive. |
| Rank features from a fitted model | FeatureImportances |
Estimator must expose feature_importances_ or coef_; pass labels, relative, absolute, stack, and topn deliberately. |
| Estimate how many random features are enough | DroppingCurve |
Bounded feature_sizes, explicit cv, scoring, n_jobs, and random_state; trains many clones. |
Required read order for future agents
- Read API reference for import paths, signatures, learned attributes, and validation constraints.
- Read workflows for bounded recipes covering k selection, CV/scoring/n_jobs choices, feature ranking, RFECV, and dropping curves.
- If anything fails, read troubleshooting and then root troubleshooting for shared install/display/compatibility issues.
- Run model_selection_smoke.py with synthetic data when you need a safe local check. It forces Matplotlib
Agg, performs no network access, and writes PNGs plusmanifest.json.
Minimal k-selection workflow
import matplotlib
matplotlib.use("Agg")
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
from yellowbrick.cluster import KElbowVisualizer, SilhouetteVisualizer
X, _ = make_blobs(n_samples=240, n_features=6, centers=4, random_state=42)
elbow = KElbowVisualizer(
KMeans(random_state=42, n_init=10),
k=(2, 8),
metric="distortion",
timings=False,
)
elbow.fit(X)
elbow.show(outpath="k_elbow.png", clear_figure=True, bbox_inches="tight")
chosen_k = elbow.elbow_value_ or 4
sil = SilhouetteVisualizer(KMeans(n_clusters=chosen_k, random_state=42, n_init=10))
sil.fit(X)
sil.show(outpath="silhouette.png", clear_figure=True, bbox_inches="tight")
Do not treat elbow_value_ is None as a hard failure. A smooth elbow curve often means the data are not strongly clustered or the candidate range/metric is not informative; compare metric="silhouette", metric="calinski_harabasz", and explicit silhouette plots before recommending a final k.
Minimal model-selection workflow
import numpy as np
import matplotlib
matplotlib.use("Agg")
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import StratifiedKFold
from yellowbrick.model_selection import ValidationCurve, CVScores
X, y = make_classification(
n_samples=180, n_features=10, n_informative=5, random_state=42
)
cv = StratifiedKFold(n_splits=3, shuffle=True, random_state=42)
validation = ValidationCurve(
LogisticRegression(max_iter=1000, solver="liblinear"),
param_name="C",
param_range=np.logspace(-2, 1, 4),
logx=True,
cv=cv,
scoring="f1_weighted",
n_jobs=1,
)
validation.fit(X, y)
validation.show(outpath="validation_curve.png", clear_figure=True, bbox_inches="tight")
scores = CVScores(
LogisticRegression(max_iter=1000, solver="liblinear"),
cv=cv,
scoring="f1_weighted",
)
scores.fit(X, y)
scores.show(outpath="cv_scores.png", clear_figure=True, bbox_inches="tight")
Expensive-run controls
Model-selection visualizers clone and fit estimators many times. Before running on user data, bound the work:
- Use synthetic or sampled data first to validate imports, scoring, and output paths.
- Set explicit
cvwith a small fold count during exploration; increase folds only after the visualizer works. - Keep
param_range,train_sizes, andfeature_sizesshort; expand ranges in a second pass. - Use
n_jobs=1for debuggability and memory-constrained agents. Raisen_jobsonly when the estimator is thread/process safe and the host has capacity. - Use
pre_dispatch="2*n_jobs"or another bounded value when parallel jobs allocate large arrays. - Set
random_stateon estimators, CV splitters, andDroppingCurvefor reproducible review artifacts. - Prefer
show(outpath=..., clear_figure=True, bbox_inches="tight")over interactive display in scripts and CI.
Validation checklist
Before handing off a cluster/model-selection result:
- Confirm the task belongs here rather than classifier/regressor score-plot sub-skills.
- Confirm the estimator exposes the methods/attributes required by the chosen visualizer.
- Confirm
param_name,param_range,train_sizes,feature_sizes,cv,scoring,n_jobs, andpre_dispatchare explicit and bounded. - Confirm saved output files are non-empty under a non-interactive Matplotlib backend.
- Inspect learned attributes such as
k_values_,k_scores_,silhouette_score_,train_scores_mean_,test_scores_mean_,cv_scores_,features_,feature_importances_,support_,ranking_, andvalid_scores_mean_before summarizing conclusions. - If an elbow is not detected, report uncertainty and recommend alternate metrics/ranges instead of inventing a best
k.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).