Guide for applied machine learning with scikit-learn covering feature engineering, model selection, pipeline construction, evaluation, hyperparameter tuning, and production-ready model patterns.
A skill is a written procedure a bot loads when a job calls for it. This one is a single file, SKILL.md, and the whole file is on this page.
You are an expert applied data scientist who builds robust machine learning pipelines with scikit-learn, engineering features methodically, selecting models systematically, and evaluating results rigorously.
When to Use
Use this skill when:
User asks about python data scientist techniques or best practices
User needs guidance on python data scientist concepts
Guide for applied machine learning with scikit-learn covering feature engineering, model selection, pipeline construction, evaluation, hyperparameter tuning, and production-ready model patterns.
How much does it cost?+
Nothing. It ships with Murage, which is open source. Your bots run on the AI plan you already have.
Can I change it?+
Yes. Open it in Settings → Skills to read, edit or duplicate it. Skill Guard scans it again after every edit.
Give your first job to Murage.
Download the app, connect the AI you already pay for, and tell your Chief of Staff what needs doing. Plan on about ten minutes from install to a working team.
What it teaches a bot, what it covers, and the whole file to read.
The principle
“
You are an expert applied data scientist who builds robust machine learning pipelines with scikit-learn, engineering features methodically, selecting models systematically, and evaluating results rigorously.
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import (
StandardScaler, MinMaxScaler, RobustScaler,
PowerTransformer, QuantileTransformer
)
from sklearn.impute import SimpleImputer
import numpy as np
numeric_pipeline = Pipeline([
('imputer', SimpleImputer(strategy='median')),
('scaler', RobustScaler()), # Robust to outliers
])
# When to use each scaler:
# StandardScaler - Normal-ish data, linear models, SVMs
# MinMaxScaler - Neural networks, bounded features
# RobustScaler - Data with outliers
# PowerTransformer - Skewed distributions (Box-Cox, Yeo-Johnson)
# QuantileTransformer - Force uniform or normal distribution
Categorical Features
python
from sklearn.preprocessing import (
OneHotEncoder, OrdinalEncoder, TargetEncoder
)
# One-hot: low cardinality (<15 categories)
ohe = OneHotEncoder(
drop='if_binary', # Drop redundant column for binary
handle_unknown='ignore', # Handle unseen categories at predict time
sparse_output=True, # Memory efficient for high-dim
min_frequency=0.01, # Group rare categories
)
# Ordinal: ordered categories
ordinal = OrdinalEncoder(
categories=[['low', 'medium', 'high', 'critical']],
handle_unknown='use_encoded_value',
unknown_value=-1,
)
# Target encoding: high cardinality (cities, zip codes)
target_enc = TargetEncoder(
smooth='auto', # Regularization
target_type='continuous',
)
from sklearn.model_selection import (
StratifiedKFold, TimeSeriesSplit, GroupKFold,
RepeatedStratifiedKFold
)
# Imbalanced classification
cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
# Time series (no data leakage)
cv = TimeSeriesSplit(n_splits=5, gap=7) # 7-day gap between train/test
# Grouped data (e.g., same user in train and test)
cv = GroupKFold(n_splits=5)
scores = cross_val_score(pipeline, X, y, cv=cv, groups=user_ids)
# More robust estimate
cv = RepeatedStratifiedKFold(n_splits=5, n_repeats=3, random_state=42)
Model Serialization
python
import joblib
from pathlib import Path
from datetime import datetime
def save_model(pipeline, metrics, model_dir='models'):
"""Save model with metadata."""
model_dir = Path(model_dir)
model_dir.mkdir(exist_ok=True)
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
model_path = model_dir / f'model_{timestamp}.joblib'
meta_path = model_dir / f'model_{timestamp}_meta.json'
# Save model
joblib.dump(pipeline, model_path)
# Save metadata
import json
metadata = {
'timestamp': timestamp,
'metrics': metrics,
'features': list(pipeline.named_steps['preprocessor'].get_feature_names_out()),
'model_type': type(pipeline.named_steps['classifier']).__name__,
'model_path': str(model_path),
}
with open(meta_path, 'w') as f:
json.dump(metadata, f, indent=2, default=str)
print(f"Model saved to {model_path}")
return model_path
Common Pitfalls
Pitfall
Symptom
Fix
Data leakage
Unrealistically high test performance
Fit preprocessing only on train data
Target leakage
Feature contains future information
Audit feature timestamps
Class imbalance
High accuracy, low recall
Use stratified CV, SMOTE, class weights
Overfitting
Train >> test performance
Regularization, simpler model, more data
Feature scale issues
Linear model ignores some features
Scale all numeric features
Missing value patterns
Model fails on new data
Handle unknowns in encoders
Train/serve skew
Good offline, bad online
Use same pipeline for train and predict
Temporal leakage
Random CV on time series
Use TimeSeriesSplit
Process
Gather information. Ask the user clarifying questions to understand their specific situation, goals, and constraints
Analyze context. Review the information provided and identify key factors relevant to python data scientist
Develop recommendations. Apply domain expertise to create actionable guidance tailored to the user's needs
Present structured output. Deliver findings in the output format below with clear next steps
Address follow-ups. Answer additional questions and refine recommendations based on feedback