跳到正文
cccskills
免费在 GitHub 公开

scikit-learn-best-practices

Best practices for scikit-learn machine learning, model development, evaluation, and deployment in Python

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md4.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

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() with random_state for 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 StandardScaler for normally distributed features
  • Use MinMaxScaler for bounded features
  • Use RobustScaler for data with outliers
  • Encode categorical variables: OneHotEncoder, OrdinalEncoder, LabelEncoder
  • Handle missing values: SimpleImputer, KNNImputer

Pipelines

  • Always use Pipeline to 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 ColumnTransformer for 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 evaluation
  • cross_validate() for multiple metrics
  • Use appropriate CV strategy:
    • KFold for regression
    • StratifiedKFold for classification
    • TimeSeriesSplit for temporal data
    • GroupKFold for grouped data

Hyperparameter Tuning

  • Use GridSearchCV for exhaustive search
  • Use RandomizedSearchCV for large parameter spaces
  • Always tune on training/validation data, never test data
  • Set n_jobs=-1 for parallel processing

Model Evaluation

Classification Metrics

  • Use appropriate metrics for your problem:
    • accuracy_score for balanced classes
    • precision_score, recall_score, f1_score for imbalanced
    • roc_auc_score for ranking ability
  • Use classification_report() for comprehensive overview
  • Examine confusion_matrix() for error analysis

Regression Metrics

  • mean_squared_error (MSE) for general use
  • mean_absolute_error (MAE) for interpretability
  • r2_score for 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 SelectKBest with statistical tests
  • Use RFE (Recursive Feature Elimination)
  • Use model-based selection: SelectFromModel
  • Examine feature importances from tree-based models

Model Persistence

  • Use joblib for saving and loading models
  • Save entire pipelines, not just models
  • Version control model artifacts
  • Document model metadata

Performance Optimization

  • Use n_jobs=-1 for parallel processing where available
  • Consider warm_start=True for 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_state for reproducibility
  • Use pipelines to prevent data leakage
  • Document model choices and hyperparameters

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

12-agent academic paper writing pipeline. 10 modes (full/plan/outline/revision/revision-coach/abstract/lit-review/format-convert/citation-check/disclosure). 6 paper types, 5 citation formats, bilingual abstracts, LaTeX/DOCX-via-Pandoc/PDF output. Style Calibration + Writing Quality Check + Anti-Patterns with IRON RULE markers. Triggers: write paper, academic paper, guide my paper, parse reviews, AI disclosure, 寫論文, 學術論文, 引導我寫論文, 審查意見.

中文简介正在准备中。当前显示原文说明。

bouclem/skills72026年5月31日 更新

Multi-perspective academic paper review with dynamic reviewer personas. Simulates 5 independent reviewers (EIC + 3 peer reviewers + Devil's Advocate) with field-specific expertise. Supports full review, re-review (verification), quick assessment, methodology focus, Socratic guided, and calibration modes. Triggers on: review paper, peer review, manuscript review, referee report, review my paper, critique paper, simulate review, editorial review, calibrate reviewer, reviewer calibration, measure reviewer accuracy.

中文简介正在准备中。当前显示原文说明。

bouclem/skills72026年5月31日 更新

Orchestrator for the full academic research pipeline: research -> write -> integrity check -> review -> revise -> re-review -> re-revise -> final integrity check -> finalize. Coordinates deep-research, academic-paper, and academic-paper-reviewer into a seamless 10-stage workflow with mandatory integrity verification, two-stage peer review, and reproducible quality gates. Triggers on: academic pipeline, research to paper, full paper workflow, paper pipeline, end-to-end paper, research-to-publication, complete paper workflow.

中文简介正在准备中。当前显示原文说明。

bouclem/skills72026年5月31日 更新

Create, iterate, and scale paid ad creative for Google Ads, Meta, LinkedIn, TikTok, and similar platforms. Use when generating headlines, descriptions, primary text, or large sets of ad variations for testing and performance optimization.

中文简介正在准备中。当前显示原文说明。

bouclem/skills72026年5月31日 更新

This skill should be used when the user asks to "implement LLM-as-judge", "compare model outputs", "create evaluation rubrics", "mitigate evaluation bias", or mentions direct scoring, pairwise comparison, position bias, evaluation pipelines, or automated quality assessment.

中文简介正在准备中。当前显示原文说明。

bouclem/skills72026年5月31日 更新

AI agent development workflow for building autonomous agents, multi-agent systems, and agent orchestration with CrewAI, LangGraph, and custom agents.

中文简介正在准备中。当前显示原文说明。

bouclem/skills72026年5月31日 更新

查看 bouclem 的全部技能

报告此技能的问题