
Scikit Learn
Train, validate, and compare scikit-learn models with correct splits, cross-validation, and hyperparameter tuning while you ship ML features solo.
Overview
Scikit-learn is an agent skill most often used in Build (also Validate) that guides model selection, train-test splits, and cross-validation with scikit-learn's model_selection tools.
Install
npx skills add https://github.com/davila7/claude-code-templates --skill scikit-learnWhat is this skill?
- Train-test and stratified splits with reproducible random_state
- KFold and StratifiedKFold walkthroughs for balanced evaluation
- Three-way train/validation/test split pattern for tuning without leakage
- Cross-validation loop templates ready to paste into notebooks or services
- Model-selection tooling aligned with scikit-learn's official APIs
- Documents KFold and StratifiedKFold with n_splits=5 examples
- Includes default 75/25 train_test_split and three-way 70/15/15-style split pattern
Adoption & trust: 692 installs on skills.sh; 27.8k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You have labeled data and a sklearn estimator but no consistent split, CV strategy, or tuning workflow—and you risk optimistic metrics from leakage or wrong folds.
Who is it for?
Solo builders adding sklearn classifiers or regressors to a product who want copy-paste-correct splitting and CV without re-reading the docs each sprint.
Skip if: Teams that already standardize on PyTorch-only pipelines, managed AutoML, or production monitoring—skip if you only need deployment manifests, not offline evaluation.
When should I use this skill?
You are choosing evaluation strategy, implementing train_test_split or cross-validation, or tuning sklearn models in Python.
What do I get? / Deliverables
You get reproducible split/CV patterns and evaluation structure your agent can implement in Python before you lock a model for deployment.
- Train/val/test split code
- Cross-validation loop using KFold or StratifiedKFold
- Evaluation-ready dataset partitions with random_state=42
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Model selection and evaluation are core build work when your product includes classification, regression, or ranking—not optional polish after launch. Backend and data-layer code is where train/test splits, CV strategies, and estimators live in a typical indie SaaS or API.
Where it fits
Compare two classifiers on a scraped dataset with a proper holdout before you commit to a build sprint.
Add a training script with StratifiedKFold and fixed random_state for a billing-risk or churn model.
Document evaluation protocol in tests so CI fails if someone trains on the full test set.
How it compares
Reference skill for sklearn evaluation workflows—not a hosted notebook, MCP server, or hyperparameter search SaaS.
Common Questions / FAQ
Who is scikit-learn for?
Indie and solo builders shipping Python ML features who want their coding agent to follow sklearn best practices for splits and cross-validation.
When should I use scikit-learn?
During validate when you prototype model quality on a sample dataset, and during build when you wire training/evaluation scripts, choose StratifiedKFold for imbalanced labels, or set up a train/val/test split before tuning.
Is scikit-learn safe to install?
Treat it like any third-party skill: review the Security Audits panel on this Prism page and inspect the SKILL.md source before letting an agent run code on your data.
SKILL.md
READMESKILL.md - Scikit Learn
# Model Selection and Evaluation Reference ## Overview Comprehensive guide for evaluating models, tuning hyperparameters, and selecting the best model using scikit-learn's model selection tools. ## Train-Test Split ### Basic Splitting ```python from sklearn.model_selection import train_test_split # Basic split (default 75/25) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42) # With stratification (preserves class distribution) X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.25, stratify=y, random_state=42 ) # Three-way split (train/val/test) X_train, X_temp, y_train, y_temp = train_test_split(X, y, test_size=0.3, random_state=42) X_val, X_test, y_val, y_test = train_test_split(X_temp, y_temp, test_size=0.5, random_state=42) ``` ## Cross-Validation ### Cross-Validation Strategies **KFold** - Standard k-fold cross-validation - Splits data into k consecutive folds ```python from sklearn.model_selection import KFold kf = KFold(n_splits=5, shuffle=True, random_state=42) for train_idx, val_idx in kf.split(X): X_train, X_val = X[train_idx], X[val_idx] y_train, y_val = y[train_idx], y[val_idx] ``` **StratifiedKFold** - Preserves class distribution in each fold - Use for imbalanced classification ```python from sklearn.model_selection import StratifiedKFold skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42) for train_idx, val_idx in skf.split(X, y): X_train, X_val = X[train_idx], X[val_idx] y_train, y_val = y[train_idx], y[val_idx] ``` **TimeSeriesSplit** - For time series data - Respects temporal order ```python from sklearn.model_selection import TimeSeriesSplit tscv = TimeSeriesSplit(n_splits=5) for train_idx, val_idx in tscv.split(X): X_train, X_val = X[train_idx], X[val_idx] y_train, y_val = y[train_idx], y[val_idx] ``` **GroupKFold** - Ensures samples from same group don't appear in both train and validation - Use when samples are not independent ```python from sklearn.model_selection import GroupKFold gkf = GroupKFold(n_splits=5) for train_idx, val_idx in gkf.split(X, y, groups=group_ids): X_train, X_val = X[train_idx], X[val_idx] y_train, y_val = y[train_idx], y[val_idx] ``` **LeaveOneOut (LOO)** - Each sample used as validation set once - Use for very small datasets - Computationally expensive ```python from sklearn.model_selection import LeaveOneOut loo = LeaveOneOut() for train_idx, val_idx in loo.split(X): X_train, X_val = X[train_idx], X[val_idx] y_train, y_val = y[train_idx], y[val_idx] ``` ### Cross-Validation Functions **cross_val_score** - Evaluate model using cross-validation - Returns array of scores ```python from sklearn.model_selection import cross_val_score from sklearn.ensemble import RandomForestClassifier model = RandomForestClassifier(n_estimators=100, random_state=42) scores = cross_val_score(model, X, y, cv=5, scoring='accuracy') print(f"Scores: {scores}") print(f"Mean: {scores.mean():.3f} (+/- {scores.std() * 2:.3f})") ``` **cross_validate** - More comprehensive than cross_val_score - Can return multiple metrics and fit times ```python from sklearn.model_selection import cross_validate model = RandomForestClassifier(n_estimators=100, random_state=42) cv_results = cross_validate( model, X, y, cv=5, scoring=['accuracy', 'precision', 'recall', 'f1'], return_train_score=True, return_estimator=True # Returns fitted estimators ) print(f"Test accuracy: {cv_results['test_accuracy'].mean():.3f}") print(f"Test precision: {cv_results['test_precision'].mean():.3f}") print(f"Fit time: {cv_results['fit_time'].mean():.3f}s") ``` **cross_val_predict** - Get predictions for each sample when it was in validation set - Useful for analyzing errors ```python from sklearn.model_selection import cross_val_predict model = RandomForestClassifier(n_estimators=100, random_state=42) y_pred = cross_val_predict(model, X, y, cv=5) # Now can analyze predictions vs actual