scikit-learn – skill Dữ liệu & Khoa học cho agent AI
Hỗ trợ học máy trong Python với scikit-learn. Áp dụng khi làm việc với học có giám sát (phân loại, hồi quy), học không giám sát (phân cụm, giảm chiều), đánh giá mô hình, tinh chỉnh hyperparameter, tiền xử lý, hoặc xây dựng ML pipeline. Cung cấp tài liệu tham khảo toàn diện
Cài skill scikit-learn bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/scikit-learn-03e1c.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /scikit-learn – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/scikit-learn-03e1c.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $scikit-learn – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/scikit-learn-03e1c.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /scikit-learn – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/scikit-learn-03e1c.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /scikit-learn – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Scikit-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
Targets scikit-learn 1.9.1, verified with Python 3.13. The release requires Python 3.11+; use its published wheels for your interpreter/platform. See the [1.9 release notes](https://scikit-learn.org/stable/whats_new/v1.9.html). The bundled scripts and regression tests are executable examples. Reference snippets using caller-provided X, y, columns, or placeholders are illustrative adaptations, not complete standalone programs.
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.9.1"
# Optional: plotting utilities and bundled script dependencies
uv pip install "scikit-learn[plots]==1.9.1" matplotlib pandas
# Commonly used with
uv pip install pandas numpyCheck 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](references/core_capabilities.md), with per-topic detail
in [references/supervised_learning.md](references/supervised_learning.md),
[references/unsupervised_learning.md](references/unsupervised_learning.md),
[references/model_evaluation.md](references/model_evaluation.md),
[references/preprocessing.md](references/preprocessing.md), and
[references/pipelines_and_composition.md](references/pipelines_and_composition.md):
1. Supervised learning — classification and regression estimator families.
2. Unsupervised learning — clustering, decomposition, and manifold learning.
3. Model evaluation and selection — metrics, cross-validation, and hyperparameter search.
4. Data preprocessing — scaling, encoding, imputation, and feature selection.
5. Pipelines and composition — Pipeline and ColumnTransformer.
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](references/common_workflows.md).
Example Scripts
Run these commands from this skill directory; the clustering demo writes PNGs into the working directory. Its synthetic noise is seeded. The classification script assumes independent rows with enough observations per class for stratified CV; adapt both splits for grouped or temporal data.
Classification Pipeline
Run a complete classification workflow with preprocessing, model comparison, hyperparameter tuning, and evaluation:
uv run --no-project --with scikit-learn==1.9.1 --with pandas --with matplotlib python scripts/classification_pipeline.pyThis script demonstrates:
- Handling mixed data types (numeric and categorical)
- Model comparison using stratified cross-validation and balanced accuracy by default
- Hyperparameter tuning with GridSearchCV
- Comprehensive evaluation with multiple metrics
- Impurity feature importances, with their high-cardinality bias made explicit
Clustering Analysis
Perform clustering analysis with algorithm comparison and visualization:
uv run --no-project --with scikit-learn==1.9.1 --with pandas --with matplotlib python scripts/clustering_analysis.pyThis script demonstrates:
- Exploring candidate cluster counts (inertia/elbow and silhouette analysis)
- Comparing multiple clustering algorithms (K-Means, DBSCAN, Agglomerative, Gaussian Mixture)
- Reporting undefined metrics for degenerate clusterings and DBSCAN noise coverage
- Assessing internal geometry without treating it as proof of scientific clusters
- 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]))Match the Split to the Independent Unit
For independent classification rows, preserve class distribution as below. For repeated patients, specimens, sites, or related molecules, keep each group entirely in one partition using GroupKFold or StratifiedGroupKFold; class stratification alone does not prevent group leakage. For future prediction, use a chronological spli
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- deep-research – Thực hiện các tác vụ nghiên cứu tự động: lập kế hoạch, tìm kiếm, đọc và tổng hợp thông…
- deep-research-framework – Khung làm báo cáo nghiên cứu chuyên sâu: xác định câu hỏi và phân loại nguồn trước, kiểm…
- dependency-analysis – Phân tích phụ thuộc nội bộ và gói bên ngoài bằng duyệt đồ thị Ontoly. Dùng khi được hỏi…
- spark-optimization – Tối ưu job Apache Spark với phân vùng, caching, tối ưu shuffle và tinh chỉnh bộ nhớ…
- scvelo – Thực hiện phân tích RNA velocity với scVelo từ số lượng RNA spliced và unspliced đơn…
- dependency-upgrade – Thành thạo nâng cấp phiên bản phụ thuộc lớn, phân tích tương thích, chiến lược nâng cấp…
- spark-training-gotchas – Kiểm tra trước và chẩn đoán 10 lỗi đã biết khi huấn luyện ML trên NVIDIA DGX Spark. Dùng…
- scvi-tools – Khớp mô hình xác suất cho omics đơn bào, gồm tích hợp batch scVI, chú thích scANVI…