scikit-learn-best-practices
Skill266 starsChanged 10 months agoApache-2.0View on GitHub
Best practices for scikit-learn machine learning, model development, evaluation, and deployment in Python
In this repository264 other files it gives its agents.
- accessibility-a11ySkill
- alpine-jsSkill
- analytics-data-analysisSkill
- android-developmentSkill
- angular-developmentSkill
- angularSkill
- anime-jsSkill
- anthropic-claude-developmentSkill
- api-developmentSkill
- apollo-graphqlSkill
- aspnet-coreSkill
- astroSkill
- auth0-authenticationSkill
- autogen-developmentSkill
- automl-hyperparameter-optimizationSkill
- aws-developmentSkill
- azureSkill
- backend-developmentSkill
- bash-scriptingSkill
- beautifulsoup-parsingSkill
- bitbucket-workflowSkill
- blazorSkill
- blender-python-addonSkill
- blockchainSkill
- bootstrapSkill
- business-central-developmentSkill
- cheerio-parsingSkill
- chrome-extension-developmentSkill
- ci-cd-best-practicesSkill
- clean-architectureSkill
- clean-codeSkill
- clerk-authenticationSkill
- cloudflare-developmentSkill
- computer-vision-opencvSkill
- convexSkill
- cppSkill
- c-sharpSkill
- cssSkill
- cypressSkill
- data-analysis-jupyterSkill
- data-analystSkill
- data-jupyter-pythonSkill
- deep-learning-pythonSkill
- deep-learning-pytorchSkill
- deep-learningSkill
- deno-typescriptSkill
- design-systemsSkill
- devopsSkill
- django-pythonSkill
- django-rest-api-developmentSkill
- dockerSkill
- dotnetSkill
- drizzle-ormSkill
- drupal-developmentSkill
- elasticsearch-best-practicesSkill
- electron-developmentSkill
- elixirSkill
- embedded-stm32Skill
- esbuild-bundlerSkill
- ethereumSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
35 rules. About 0 are common, 16 are distinctive, and 19 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈16
Distinctive · estimate
This author's own choices. Worth a look.
19
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Write concise, technical responses with accurate Python examples
- Distinctive: line 14
Use functional programming for data pipelines
- Distinctive: line 15
Use object-oriented programming for custom estimators
- Distinctive: line 16
Prefer vectorized operations over explicit loops
- Distinctive: line 17
Follow PEP 8 style guidelines
- Very specific: line 23
Always split data before any preprocessing: train/validation/test
- Very specific: line 24
Use train_test_split() with random_state for reproducibility
- Distinctive: line 26
Keep test set completely separate until final evaluation
- Very specific: line 31
Use StandardScaler for normally distributed features
- Very specific: line 32
Use MinMaxScaler for bounded features
- Very specific: line 33
Use RobustScaler for data with outliers
- Very specific: line 39
Always use Pipeline to chain preprocessing and modeling
- Very specific: line 57
Use ColumnTransformer for different preprocessing per feature type
- Distinctive: line 64
Use cross-validation for reliable performance estimates
- Distinctive: line 67
Use appropriate CV strategy:
- Very specific: line 75
Use GridSearchCV for exhaustive search
- Very specific: line 76
Use RandomizedSearchCV for large parameter spaces
- Distinctive: line 77
Always tune on training/validation data, never test data
- Distinctive: line 84
Use appropriate metrics for your problem:
- Very specific: line 88
Use classification_report() for comprehensive overview
- Distinctive: line 100
Use multiple metrics to understand model behavior
- Distinctive: line 106
Use stratified splitting and cross-validation
- Very specific: line 107
Consider class weights: class_weight='balanced'
- Distinctive: line 108
Use appropriate metrics (F1, AUC-PR, not accuracy)
- Very specific: line 113
Use SelectKBest with statistical tests
- Very specific: line 114
Use RFE (Recursive Feature Elimination)
- Very specific: line 115
Use model-based selection: SelectFromModel
- Very specific: line 120
Use joblib for saving and loading models
- Very specific: line 127
Use n_jobs=-1 for parallel processing where available
- Very specific: line 128
Consider warm_start=True for iterative training
- Distinctive: line 129
Use sparse matrices for high-dimensional sparse data
- Very specific: line 130
Consider incremental learning with partial_fit() for large data
- Very specific: line 134
Import from submodules: from sklearn.ensemble import RandomForestClassifier
- Distinctive: line 136
Use pipelines to prevent data leakage
- Distinctive: line 137
Document model choices and hyperparameters
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Scikit-learn Best Practices
Expert guidelines for scikit-learn development, focusing on machine learning workflows, model development, evaluation, and best practices.
Code Style and Structure
- Write concise, technical responses with accurate Python examples
- Prioritize reproducibility in machine learning workflows
- Use functional programming for data pipelines
- Use object-oriented programming for custom estimators
- Prefer vectorized operations over explicit loops
- Follow PEP 8 style guidelines
Machine Learning Workflow
Data Preparation
- Always split data before any preprocessing: train/validation/test
- Use
train_test_split()withrandom_statefor reproducibility - Stratify splits for imbalanced classification:
stratify=y - Keep test set completely separate until final evaluation
Feature Engineering
- Scale features appropriately for distance-based algorithms
- Use
StandardScalerfor normally distributed features - Use
MinMaxScalerfor bounded features - Use
RobustScalerfor data with outliers - Encode categorical variables:
OneHotEncoder,OrdinalEncoder,LabelEncoder - Handle missing values:
SimpleImputer,KNNImputer
Pipelines
- Always use
Pipelineto chain preprocessing and modeling - Prevents data leakage by fitting transformers only on training data
- Makes code cleaner and more reproducible
- Enables easy deployment and serialization
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
pipeline = Pipeline([
('scaler', StandardScaler()),
('classifier', RandomForestClassifier(random_state=42))
])Column Transformers
- Use
ColumnTransformerfor different preprocessing per feature type - Combine numeric and categorical preprocessing in single pipeline
Model Selection and Tuning
Cross-Validation
- Use cross-validation for reliable performance estimates
cross_val_score()for quick evaluationcross_validate()for multiple metrics- Use appropriate CV strategy:
KFoldfor regressionStratifiedKFoldfor classificationTimeSeriesSplitfor temporal dataGroupKFoldfor grouped data
Hyperparameter Tuning
- Use
GridSearchCVfor exhaustive search - Use
RandomizedSearchCVfor large parameter spaces - Always tune on training/validation data, never test data
- Set
n_jobs=-1for parallel processing
Model Evaluation
Classification Metrics
- Use appropriate metrics for your problem:
accuracy_scorefor balanced classesprecision_score,recall_score,f1_scorefor imbalancedroc_auc_scorefor ranking ability
- Use
classification_report()for comprehensive overview - Examine
confusion_matrix()for error analysis
Regression Metrics
mean_squared_error(MSE) for general usemean_absolute_error(MAE) for interpretabilityr2_scorefor explained variance
Evaluation Best Practices
- Report confidence intervals, not just point estimates
- Use multiple metrics to understand model behavior
- Compare against meaningful baselines
- Evaluate on held-out test set only once, at the end
Handling Imbalanced Data
- Use stratified splitting and cross-validation
- Consider class weights:
class_weight='balanced' - Use appropriate metrics (F1, AUC-PR, not accuracy)
- Adjust decision threshold based on business needs
Feature Selection
- Use
SelectKBestwith statistical tests - Use
RFE(Recursive Feature Elimination) - Use model-based selection:
SelectFromModel - Examine feature importances from tree-based models
Model Persistence
- Use
joblibfor saving and loading models - Save entire pipelines, not just models
- Version control model artifacts
- Document model metadata
Performance Optimization
- Use
n_jobs=-1for parallel processing where available - Consider
warm_start=Truefor iterative training - Use sparse matrices for high-dimensional sparse data
- Consider incremental learning with
partial_fit()for large data
Key Conventions
- Import from submodules:
from sklearn.ensemble import RandomForestClassifier - Set
random_statefor reproducibility - Use pipelines to prevent data leakage
- Document model choices and hyperparameters
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

