
Scikit-learn
FreeComprehensive machine learning toolkit for Python.
Free · Opens the source repo
What Scikit-learn does
Scikit-learn is a powerful and widely-used library for machine learning in Python, designed to provide accessible tools for a variety of tasks. This skill offers in-depth guidance on using scikit-learn for supervised learning tasks such as classification and regression, as well as unsupervised learning tasks like clustering and dimensionality reduction. With robust documentation and example scripts, users can efficiently navigate the complexities of machine learning workflows, from data preprocessing to model evaluation and hyperparameter tuning.
The skill includes numerous reference files that cover core capabilities such as supervised and unsupervised learning, model evaluation techniques, and data preprocessing methods. Users can quickly find information on algorithms, best practices, and common pitfalls, ensuring they can implement effective machine learning solutions. The included example scripts demonstrate practical applications, allowing users to see how to set up classification pipelines and perform clustering analysis.
Whether you are a beginner looking to understand the basics of machine learning or an experienced practitioner seeking to refine your skills, this scikit-learn skill provides the necessary resources. It is particularly useful for those working with structured data, as well as for projects that require interpretable models. By leveraging the capabilities of scikit-learn, users can build production-ready machine learning pipelines that are both efficient and reliable.
When to use it
Use this skill when you need to build machine learning models for classification, regression, or clustering tasks, or when you want to evaluate model performance and tune hyperparameters.
When not to use it
This skill is not suitable for deep learning tasks or when working with large datasets that require specialized frameworks like TensorFlow or PyTorch.
What you can build with it
Building a Classification Model
Use the skill to create a classification model with preprocessing steps, model training, and evaluation using scikit-learn.
Performing Clustering Analysis
Utilize the provided scripts to conduct clustering analysis, comparing different algorithms and visualizing results.
Creating ML Pipelines
Leverage the skill to build production-ready machine learning pipelines that integrate preprocessing, model training, and evaluation.
How to install Scikit-learn
View source1. Install with the skills CLI
npx skills add k-dense-ai/scientific-agent-skills/scikit-learn --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by k-dense-aiScikit-learn
Overview
This skill provides comprehensive guidance for machine learning tasks using scikit-learn, the industry-standard Python library for classical machine learning. Use this skill for classification, regression, clustering, dimensionality reduction, preprocessing, model evaluation, and building production-ready ML pipelines.
Installation
Tested against scikit-learn 1.8.0 (stable; December 2025). Requires Python 3.11–3.14 (free-threaded CPython 3.14 wheels available in 1.8+).
Install the PyPI package scikit-learn (not the deprecated sklearn package on PyPI). Import in code as sklearn.
# Install scikit-learn using uv
uv pip install "scikit-learn>=1.7"
# Optional: plotting utilities and bundled script dependencies
uv pip install "scikit-learn[plots]" matplotlib seaborn
# Commonly used with
uv pip install pandas numpy
Check your version:
import sklearn
print(sklearn.__version__)
When to Use This Skill
Use the scikit-learn skill when:
- Building classification or regression models
- Performing clustering or dimensionality reduction
- Preprocessing and transforming data for machine learning
- Evaluating model performance with cross-validation
- Tuning hyperparameters with grid or random search
- Creating ML pipelines for production workflows
- Comparing different algorithms for a task
- Working with both structured (tabular) and text data
- Need interpretable, classical machine learning approaches
Quick Start
Classification Example
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report
# Split data
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, stratify=y, random_state=42
)
# Preprocess
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Train model
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train_scaled, y_train)
# Evaluate
y_pred = model.predict(X_test_scaled)
print(classification_report(y_test, y_pred))
Complete Pipeline with Mixed Data
from sklearn.pipeline import Pipeline
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.impute import SimpleImputer
from sklearn.ensemble import GradientBoostingClassifier
# Define feature types
numeric_features = ['age', 'income']
categorical_features = ['gender', 'occupation']
# Create preprocessing pipelines
numeric_transformer = Pipeline([
('imputer', SimpleImputer(strategy='median')),
('scaler', StandardScaler())
])
categorical_transformer = Pipeline([
('imputer', SimpleImputer(strategy='most_frequent')),
('onehot', OneHotEncoder(handle_unknown='ignore'))
])
# Combine transformers
preprocessor = ColumnTransformer([
('num', numeric_transformer, numeric_features),
('cat', categorical_transformer, categorical_features)
])
# Full pipeline
model = Pipeline([
('preprocessor', preprocessor),
('classifier', GradientBoostingClassifier(random_state=42))
])
# Fit and predict
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
Core Capabilities
Five capability areas are documented in references/core_capabilities.md, with per-topic detail in references/supervised_learning.md, references/unsupervised_learning.md, references/model_evaluation.md, references/preprocessing.md, and references/pipelines_and_composition.md:
- Supervised learning — classification and regression estimator families.
- Unsupervised learning — clustering, decomposition, and manifold learning.
- Model evaluation and selection — metrics, cross-validation, and hyperparameter search.
- Data preprocessing — scaling, encoding, imputation, and feature selection.
- Pipelines and composition —
PipelineandColumnTransformer.
Always fit preprocessing inside a Pipeline so it is refit per cross-validation fold;
scaling or imputing before splitting leaks test information into training.
Two worked workflows are in references/common_workflows.md.
Example Scripts
Classification Pipeline
Run a complete classification workflow with preprocessing, model comparison, hyperparameter tuning, and evaluation:
uv run python scripts/classification_pipeline.py
This script demonstrates:
- Handling mixed data types (numeric and categorical)
- Model comparison using cross-validation
- Hyperparameter tuning with GridSearchCV
- Comprehensive evaluation with multiple metrics
- Feature importance analysis
Clustering Analysis
Perform clustering analysis with algorithm comparison and visualization:
uv run python scripts/clustering_analysis.py
This script demonstrates:
- Finding optimal number of clusters (elbow method, silhouette analysis)
- Comparing multiple clustering algorithms (K-Means, DBSCAN, Agglomerative, Gaussian Mixture)
- Evaluating clustering quality without ground truth
- Visualizing results with PCA projection
Reference Documentation
This skill includes comprehensive reference files for deep dives into specific topics:
Quick Reference
File: references/quick_reference.md
- Common import patterns and installation instructions
- Quick workflow templates for common tasks
- Algorithm selection cheat sheets
- Common patterns and gotchas
- Performance optimization tips
Supervised Learning
File: references/supervised_learning.md
- Linear models (regression and classification)
- Support Vector Machines
- Decision Trees and ensemble methods
- K-Nearest Neighbors, Naive Bayes, Neural Networks
- Algorithm selection guide
Unsupervised Learning
File: references/unsupervised_learning.md
- All clustering algorithms with parameters and use cases
- Dimensionality reduction techniques
- Outlier and novelty detection
- Gaussian Mixture Models
- Method selection guide
Model Evaluation
File: references/model_evaluation.md
- Cross-validation strategies
- Hyperparameter tuning methods
- Classification, regression, and clustering metrics
- Learning and validation curves
- Best practices for model selection
Preprocessing
File: references/preprocessing.md
- Feature scaling and normalization
- Encoding categorical variables
- Missing value imputation
- Feature engineering techniques
- Custom transformers
Pipelines and Composition
File: references/pipelines_and_composition.md
- Pipeline construction and usage
- ColumnTransformer for mixed data types
- FeatureUnion for parallel transformations
- Complete end-to-end examples
- Best practices
Best Practices
Always Use Pipelines
Pipelines prevent data leakage and ensure consistency:
# Good: Preprocessing in pipeline
pipeline = Pipeline([
('scaler', StandardScaler()),
('model', LogisticRegression())
])
# Bad: Preprocessing outside (can leak information)
X_scaled = StandardScaler().fit_transform(X)
Fit on Training Data Only
Never fit on test data:
# Good
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test) # Only transform
# Bad
scaler = StandardScaler()
X_all_scaled = scaler.fit_transform(np.vstack([X_train, X_test]))
Use Stratified Splitting for Classification
Preserve class distribution:
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, stratify=y, random_state=42
)
Set Random State for Reproducibility
model = RandomForestClassifier(n_estimators=100, random_state=42)
Choose Appropriate Metrics
- Balanced data: Accuracy, F1-score
- Imbalanced data: Precision, Recall, ROC AUC, Balanced Accuracy
- Cost-sensitive: Define custom scorer
Scale Features When Required
Algorithms requiring feature scaling:
- SVM, KNN, Neural Networks
- PCA, Linear/Logistic Regression with regularization
- K-Means clustering
Algorithms not requiring scaling:
- Tree-based models (Decision Trees, Random Forest, Gradient Boosting)
- Naive Bayes
Troubleshooting Common Issues
ConvergenceWarning
Issue: Model didn't converge
Solution: Increase max_iter or scale features
model = LogisticRegression(max_iter=1000)
Poor Performance on Test Set
Issue: Overfitting Solution: Use regularization, cross-validation, or simpler model
# Add regularization
model = Ridge(alpha=1.0)
# Use cross-validation
scores = cross_val_score(model, X, y, cv=5)
Memory Error with Large Datasets
Solution: Use algorithms designed for large data
# Use SGD for large datasets
from sklearn.linear_model import SGDClassifier
model = SGDClassifier()
# Or MiniBatchKMeans for clustering
from sklearn.cluster import MiniBatchKMeans
model = MiniBatchKMeans(n_clusters=8, batch_size=100)
Additional Resources
- Official Documentation: https://scikit-learn.org/stable/
- User Guide: https://scikit-learn.org/stable/user_guide.html
- API Reference: https://scikit-learn.org/stable/api/index.html
- Examples Gallery: https://scikit-learn.org/stable/auto_examples/index.html
Frequently asked questions about Scikit-learn
Similar skills
scvi-tools Deep Learning
Advanced tools for single-cell genomic analysis.
Arize Experiment
Evaluate and compare model performance with ease.
DEFT Mining and Embedding
Automate image mining for machine learning workflows.
TimesFM Forecasting
Zero-shot time series forecasting with Google’s TimesFM.
SHAP
Audit and explain machine learning predictions with SHAP.
scvi-tools
Advanced tools for single-cell omics analysis.
