fuyu12345/terminalgen-skills/cross-validation-sklearn-medium

Claude Code and agent skill by fuyu12345/terminalgen-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Build a reproducible sklearn cross-validation pipeline for mixed-type tabular data, then emit summary metrics JSON. Use when a task requires replacing unstable train/test evaluation with k-fold results.

Install

npx vskill@latest install fuyu12345/terminalgen-skills/cross-validation-sklearn-medium

SKILL.md

The same SKILL.md was published earlier as fuyu12345/terminalgen-skills/cross-validation-sklearn-medium.

Evaluating sklearn Models with Cross-Validation

When to Use

  • Evaluate multiple classifiers on a tabular dataset with both numeric and categorical columns.
  • Require robust metrics (mean/std across folds) instead of a single split.
  • Need deterministic behavior (random_state=42) and strict JSON output for grading/automation.
  • Need a terminal-safe, one-shot script that writes results to a required path.

Minimal Reliable Workflow

  1. Load data and split target
  • Read CSV with pandas.
  • Set X = df.drop(columns=[target_col]), y = df[target_col].
  1. Detect feature types
  • Build categorical_cols from object/category/bool.
  • Treat remaining columns as numeric.
  1. Build preprocessing inside a pipeline
  • Use ColumnTransformer with:
  • categorical: OneHotEncoder(handle_unknown='ignore')
  • numeric: passthrough (or optional imputation if required).
  • Keep preprocessing inside sklearn Pipeline to avoid leakage during CV.
  1. Define CV strategy for reproducibility
  • Use StratifiedKFold(n_splits=5, shuffle=True, random_state=42) for binary classification.
  1. Evaluate each model with identical CV
  • Wrap each model in Pipeline([('preprocess', ...), ('model', ...)]).
  • Run cross_val_score(..., scoring='accuracy').
  • Compute and round:
  • mean_accuracy = round(scores.mean(), 4)
  • std_accuracy = round(scores.std(), 4)
  1. Write strict JSON schema
  • Save to required location (create parent dir first).
  • Use stable keys expected by tests, e.g.:
  • logistic_regression
  • random_forest
  • gradient_boosting
  1. Confirm file content before completion
  • cat the JSON and sanity-check keys and value ranges.

Common Pitfalls

  • Marking completion before command output flushes
  • In two runs, heredoc execution looked incomplete until waiting briefly; verification commands appeared delayed.
  • Prevent by polling ("" wait command) and confirming prompt/output before finalizing.
  • Command concatenation from missing newline
  • One run emitted a warning: a command without terminal newline can concatenate with the next command.
  • Prevent by ending every command string with \n.
  • Preprocessing outside CV pipeline
  • Causes leakage and inflated metrics.
  • Prevent by embedding ColumnTransformer in per-model Pipeline.
  • Non-reproducible splits/models
  • Omitting shuffle=True + random_state in CV (and model random states where applicable) makes run-to-run numbers unstable.
  • Output schema drift
  • Tests expect exact top-level model keys and metric field names; extra nesting or renamed fields can fail validation.

Verification Strategy

Use a two-layer verification aligned to observed test expectations:

  1. Artifact checks
  • Confirm file exists at required path.
  • Confirm valid JSON parse.
  1. Schema + metric checks
  • Assert top-level keys for all required models.
  • Assert each model has mean_accuracy and std_accuracy.
  • Assert 0 <= mean_accuracy <= 1.
  • Assert std_accuracy >= 0.
  • Assert rounding/precision to 4 decimals in serialized values.
  1. Methodology checks
  • Confirm 5-fold stratified CV with fixed random state.
  • Confirm categorical handling via encoder in pipeline.
  1. Terminal reliability checks
  • Wait for heredoc completion if output is pending.
  • Re-run cat and (optionally) a short Python assert block before final submission.

References to Load On Demand

  • sklearn.pipeline.Pipeline
  • sklearn.compose.ColumnTransformer
  • sklearn.model_selection.StratifiedKFold, cross_val_score
  • sklearn.preprocessing.OneHotEncoder

Security

  • Security scanPassed, 98 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/fuyu12345/terminalgen-skills/cross-validation-sklearn-medium/badge)](https://verified-skill.com/skills/fuyu12345/terminalgen-skills/cross-validation-sklearn-medium)

Something wrong with this skill or its page? Tell us.