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-mediumSKILL.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
- Load data and split target
- Read CSV with pandas.
- Set
X = df.drop(columns=[target_col]),y = df[target_col].
- Detect feature types
- Build
categorical_colsfromobject/category/bool. - Treat remaining columns as numeric.
- Build preprocessing inside a pipeline
- Use
ColumnTransformerwith: - categorical:
OneHotEncoder(handle_unknown='ignore') - numeric: passthrough (or optional imputation if required).
- Keep preprocessing inside sklearn
Pipelineto avoid leakage during CV.
- Define CV strategy for reproducibility
- Use
StratifiedKFold(n_splits=5, shuffle=True, random_state=42)for binary classification.
- 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)
- Write strict JSON schema
- Save to required location (create parent dir first).
- Use stable keys expected by tests, e.g.:
logistic_regressionrandom_forestgradient_boosting
- Confirm file content before completion
catthe 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
ColumnTransformerin per-modelPipeline.
- Non-reproducible splits/models
- Omitting
shuffle=True+random_statein 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:
- Artifact checks
- Confirm file exists at required path.
- Confirm valid JSON parse.
- Schema + metric checks
- Assert top-level keys for all required models.
- Assert each model has
mean_accuracyandstd_accuracy. - Assert
0 <= mean_accuracy <= 1. - Assert
std_accuracy >= 0. - Assert rounding/precision to 4 decimals in serialized values.
- Methodology checks
- Confirm 5-fold stratified CV with fixed random state.
- Confirm categorical handling via encoder in pipeline.
- Terminal reliability checks
- Wait for heredoc completion if output is pending.
- Re-run
catand (optionally) a short Python assert block before final submission.
References to Load On Demand
sklearn.pipeline.Pipelinesklearn.compose.ColumnTransformersklearn.model_selection.StratifiedKFold,cross_val_scoresklearn.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
- SKILL.md in the repositoryCheckinggenerated_skills/cross_validation_sklearn_medium/SKILL.md
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
[](https://verified-skill.com/skills/fuyu12345/terminalgen-skills/cross-validation-sklearn-medium)