refactor:scikit-learn

Refactor scikit-learn ML code into Pipelines with ColumnTransformer and deterministic random_state.

9|1|Updated Jan 12, 2026
One-click install
npx skills add https://github.com/SnakeO/claude-debug-and-refactor-skills-plugin --skill refactor-scikit-learn
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor:scikit-learn
Source: https://github.com/SnakeO/claude-debug-and-refactor-skills-plugin/tree/main/plugins/debug-and-refactor/skills/refactor-scikit-learn
Command: npx skills add https://github.com/SnakeO/claude-debug-and-refactor-skills-plugin --skill refactor-scikit-learn

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill converts fragmented ML scripts into cohesive, production-ready pipelines, eliminating data leakage risks and improving reproducibility across experiments.

Core Features & Use Cases

  • Pipeline-first design: encapsulates preprocessing and modeling in a single Pipeline to prevent leakage.
  • ColumnTransformer & Custom Transformers: handles heterogeneous data and customizable feature engineering while maintaining API compatibility.
  • Robust evaluation patterns: enforces proper cross-validation, fixed random_state, and systematic hyperparameter tuning for reliable comparisons.

Quick Start

Refactor the provided scikit-learn script to implement a Pipeline with a ColumnTransformer, validate with cross-validation, and set deterministic random_state. Then run the refactored code on your dataset and compare results to the original workflow.

Frequently Asked Questions about refactor:scikit-learn

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent data leakage when building a scikit-learn pipeline?

Prevent data leakage in scikit-learn by encapsulating preprocessing, feature engineering, and modeling steps within a single Pipeline and ColumnTransformer, ensuring transformations are fitted only on training data during cross-validation.

How do I refactor machine learning code to use scikit-learn best practices?

Refactor machine learning code by moving fragmented scripts into a unified scikit-learn Pipeline, applying ColumnTransformer for heterogeneous data, enforcing deterministic random_state, and using cross-validation to ensure reproducible experiments.

Does scikit-learn ColumnTransformer work with custom transformers for feature engineering?

Yes, scikit-learn ColumnTransformer works with custom transformers for feature engineering as long as they conform to the sklearn API, allowing you to handle heterogeneous data while maintaining pipeline compatibility and preventing data leakage.

What is the best way to ensure reproducibility across scikit-learn experiments?

The best way to ensure reproducibility across scikit-learn experiments is to set a deterministic random_state for all algorithms and encapsulate your workflow in a Pipeline with systematic hyperparameter tuning and proper cross-validation.

Why does my scikit-learn cross-validation produce inconsistent results?

Scikit-learn cross-validation produces inconsistent results when random_state is not fixed or preprocessing steps are applied outside the Pipeline, causing data leakage. Encapsulate transformations in a Pipeline and set deterministic seeds.