debug-scikit-learn_skill

This skill helps you debug scikit-learn issues systematically, diagnosing common errors like shape mismatches, not fitted, NaNs, leakage, and convergence

6

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill snakeo/claude-debug-and-refactor-skills-plugin --skill debug-scikit-learn

  • SKILL.md20.6 KB

Overview

This skill helps you systematically debug Scikit-learn pipelines, models, and preprocessing steps to find root causes of common errors. It guides inspection of shapes, fitted state, NaNs/infinities, pipeline configuration, convergence warnings, cross-validation and leakage. Use it to get a concise diagnosis and actionable fixes so you can restore correct model training and evaluation.

How this skill works

It inspects input data, transformer outputs, and model attributes to detect mismatched feature counts, missing fits, NaN/inf values, and misconfigured pipelines. It runs diagnostic checks for cross-validation setup, class imbalance, learning-curve signals, and optimizer convergence warnings, and it prints targeted remediation steps. The skill recommends concrete code patterns (Pipeline, ColumnTransformer, imputers, scaling, CV choices) to prevent recurrence.

When to use it

  • You get ValueError about shape mismatch between train/test or model expectation
  • NotFittedError or predict/transform called before fit
  • ValueError complaining about NaN or infinity in input
  • ConvergenceWarning or optimizer failing to converge
  • Cross-validation failing because of too few samples or severe class imbalance
  • Suspiciously high scores that suggest data leakage

Best practices

  • Wrap preprocessing and estimator inside a Pipeline to avoid train/test leakage
  • Use ColumnTransformer with handle_unknown or remainder to align features between splits
  • Validate data early: shapes, dtypes, NaN/Inf, value ranges, and class distribution
  • Check fitted attributes (names ending with _) and use check_is_fitted before predict/transform
  • Scale features and increase max_iter or change solver for persistent convergence issues
  • Use stratified or specialized CV (StratifiedKFold, TimeSeriesSplit, LeaveOneOut) appropriate to the problem

Example use cases

  • Fix a shape mismatch caused by one-hot encoding that dropped categories in test set by using OneHotEncoder(handle_unknown='ignore') and consistent ColumnTransformer
  • Detect NotFittedError by checking fitted attributes and ensuring fit() or fit_transform() runs inside cross-validation folds
  • Locate NaN/Inf values, choose row removal or SimpleImputer for training, and clip extreme values before fitting
  • Address ConvergenceWarning by standardizing features, increasing max_iter, or switching solver to 'saga' or 'lbfgs' with adjusted tol
  • Diagnose apparent perfect scores by auditing preprocessing order, ensuring no target leakage, and switching to pipeline-based CV

FAQ

Use sklearn.utils.validation.check_is_fitted(model) or list attributes ending with '_' to see fitted parameters.

What to do when train and test have different columns after encoding?

Use ColumnTransformer with explicit column lists and OneHotEncoder(handle_unknown='ignore') or persist the full feature set then align columns before predict.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational