
Data Scientist
- 28 installs
- 7 repo stars
- Updated May 20, 2026
- daemon-blockint-tech/agentic-enteprises-skill
Executes data science workflows: ML modeling, statistical analysis, A/B testing, causal inference, feature engineering, model evaluation, and MLOps.
About
An agent skill for data science workflows from exploration to production, covering ML modeling, statistical analysis, A/B testing, causal inference, feature engineering, and MLOps patterns. A developer uses it when building predictive models, designing experiments, or productionizing ML.
- A/B testing, causal inference, and model evaluation
- MLOps patterns including model monitoring
Data Scientist by the numbers
- 28 all-time installs (skills.sh)
- Ranked #1,126 of 2,064 Data Science & ML skills by installs in the Skillselion catalog
- Data as of Jul 29, 2026 (Skillselion catalog sync)
npx skills add https://github.com/daemon-blockint-tech/agentic-enteprises-skill --skill data-scientistAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 28 |
|---|---|
| repo stars | ★ 7 |
| Last updated | May 20, 2026 |
| Repository | daemon-blockint-tech/agentic-enteprises-skill ↗ |
What it does
Executes data science workflows: ML modeling, statistical analysis, A/B testing, causal inference, feature engineering, model evaluation, and MLOps.
Files
Data Scientist
Overview
Execute data science workflows from exploration to production. This skill covers machine learning modeling, statistical analysis, A/B testing, causal inference, feature engineering, model evaluation, and MLOps patterns.
Features
- ML modeling lifecycle: problem framing, data prep, model selection, training, evaluation
- Statistical analysis: hypothesis testing, regression, ANOVA, Bayesian methods
- A/B testing: experiment design, sample size calculation, statistical power, result interpretation
- Causal inference: propensity score matching, difference-in-differences, instrumental variables
- Feature engineering: encoding, scaling, selection, dimensionality reduction
- MLOps: model deployment, monitoring, drift detection, retraining triggers
Usage
1. Identify the user's data science need (modeling, analysis, experimentation, or MLOps) 2. Follow the corresponding workflow below 3. Produce structured outputs: model cards, experiment reports, feature engineering pipelines, or MLOps runbooks
Examples
- User: "Build a churn prediction model"
Agent: Runs ML Modeling workflow, frames problem, selects features, trains classifier, evaluates with precision/recall, produces model card
- User: "Design an A/B test"
Agent: Runs Experiment Design workflow, calculates sample size, defines success metrics, sets up randomization, produces experiment plan
- User: "Monitor model drift"
Agent: Runs MLOps workflow, defines drift metrics, sets up monitoring dashboard, configures retraining triggers
When to Use
- Scoping ML problems, baselines, feature engineering, and model evaluation
- Designing A/B tests, power analysis, or causal inference when experiments are infeasible
- Productionizing models (batch, real-time, monitoring, retraining triggers)
- Selecting ML, stats, or MLOps tools for a given problem and data regime
When NOT to Use
- Executive dashboards, KPI definitions, or BI storytelling → use
bi-analyst - Warehouse dimensional modeling or ETL idempotency patterns → use
data-warehouse-engineer - Prompt design, LLM agents, or guardrailed GenAI features → use
prompt-engineer - RL training platform, rollout workers, distributed PPO/SAC jobs → use
ml-systems-engineer-rl-engineering - Revenue metrics (ARR, NRR) or ASC 606 accounting → use
senior-revenue-accountant
Core Workflows
1. End-to-End ML Project Workflow
Phase checklist:
1. Problem definition
- Define the business metric to optimize
- Determine if ML is needed (rule-based may suffice)
- Set success criteria and failure modes
2. Data exploration & validation
- Profile distributions, missing values, duplicates
- Check for leakage (future information in training data)
- Validate data freshness and coverage
3. Feature engineering
- Create domain-relevant features
- Encode categoricals, scale numerics
- Document feature definitions and dependencies
4. Modeling
- Baseline: simple model first (linear regression, logistic)
- Iterate: tree-based, then ensembles, then deep learning if needed
- Cross-validate properly (time-based for temporal data)
5. Evaluation
- Hold-out test set, never used for hyperparameter tuning
- Check calibration, fairness, robustness
- Compare against baseline and business threshold
6. Production
- Serialize model, build inference API
- Add monitoring (prediction drift, latency)
- Document retraining triggers
2. Statistical Analysis & Experimentation
A/B testing workflow:
1. Define hypothesis, primary metric, and minimal detectable effect (MDE) 2. Calculate sample size (power analysis) 3. Randomize and run experiment 4. Check invariant metrics (randomization sanity) 5. Analyze primary metric with proper statistical test 6. Correct for multiple comparisons if needed 7. Document and socialize results
Causal inference when A/B test is impossible:
- Difference-in-differences
- Propensity score matching
- Instrumental variables
- Regression discontinuity
3. Productionizing Models (MLOps)
Deployment patterns:
| Pattern | When | Trade-off |
|---|---|---|
| Batch scoring | Periodic predictions, no latency requirement | Simple, stale predictions between runs |
| Real-time API | User-facing, latency-sensitive | Complex, requires monitoring |
| Edge / on-device | Mobile/IoT, offline needed | Model size constraints, hard to update |
| Embedded | Database/warehouse native (BigQuery ML, Snowpark) | Limited to supported algorithms |
Monitoring checklist:
- [ ] Prediction distribution drift vs training
- [ ] Feature drift (incoming data changes)
- [ ] Latency and throughput
- [ ] Error rate and fallback behavior
- [ ] Business metric tracking
4. Tool Selection
| Task | Recommended Tools |
|---|---|
| Data manipulation | pandas, Polars, SQL |
| Feature engineering | scikit-learn, Feature-engine, Tsfresh |
| Modeling | scikit-learn, XGBoost, LightGBM, PyTorch, TensorFlow |
| Experiment tracking | MLflow, Weights & Biases, Neptune |
| Hyperparameter tuning | Optuna, Ray Tune, Hyperopt |
| Causal inference | CausalML, DoWhy, EconML |
| Interpretability | SHAP, LIME, ELI5 |
| Deployment | FastAPI, BentoML, Seldon, SageMaker |
Analytics & Statistics
Hypothesis Testing
Test Selection Guide
| Data Type | Comparison | Test |
|---|---|---|
| Continuous, normal, 2 groups | Independent | Two-sample t-test |
| Continuous, normal, 2 groups | Paired | Paired t-test |
| Continuous, non-normal, 2 groups | Independent | Mann-Whitney U |
| Continuous, >2 groups | Independent | ANOVA (parametric), Kruskal-Wallis (non-param) |
| Categorical, 2 categories | Proportions | Z-test for proportions |
| Categorical, >2 categories | Independence | Chi-square test |
| Correlation | 2 continuous | Pearson (linear), Spearman (monotonic) |
Always check assumptions:
- Independence of observations
- Normality (for parametric tests; use Shapiro-Wilk or Q-Q plot)
- Homogeneity of variance (Levene's test)
- Sample size (central limit theorem helps for n > 30)
Python Examples
from scipy import stats
# Two-sample t-test
t_stat, p_value = stats.ttest_ind(group_a, group_b, equal_var=False)
# Mann-Whitney U (non-parametric)
u_stat, p_value = stats.mannwhitneyu(group_a, group_b, alternative='two-sided')
# Chi-square test
contingency = pd.crosstab(df['category'], df['outcome'])
chi2, p_value, dof, expected = stats.chi2_contingency(contingency)
# Effect size (Cohen's d)
def cohens_d(x, y):
nx, ny = len(x), len(y)
dof = nx + ny - 2
return (np.mean(x) - np.mean(y)) / np.sqrt(((nx-1)*np.std(x, ddof=1)**2 + (ny-1)*np.std(y, ddof=1)**2) / dof)A/B Testing
Experiment Design Checklist
- [ ] Primary metric defined (single metric to optimize)
- [ ] Secondary metrics identified (guardrails, not for decision)
- [ ] Minimal Detectable Effect (MDE) set with business input
- [ ] Sample size calculated (power = 0.8, alpha = 0.05)
- [ ] Randomization unit matches analysis unit (usually user)
- [ ] Duration covers at least 1 full business cycle
- [ ] No confounding launches during experiment
Sample Size Calculation
from statsmodels.stats.power import NormalIndPower
from statsmodels.stats.proportion import proportion_effectsize
# For proportions (conversion rate)
baseline = 0.10 # 10% conversion
mde = 0.02 # Detect 12% vs 10%
effect_size = proportion_effectsize(baseline + mde, baseline)
power_analysis = NormalIndPower()
sample_size = power_analysis.solve_power(
effect_size=effect_size,
alpha=0.05,
power=0.8,
ratio=1
)
# sample_size per groupAnalysis Best Practices
1. Intent-to-treat: Analyze all randomized users, even if they didn't engage 2. Check invariant metrics: Confirm randomization worked (e.g., device split unchanged) 3. Use proper statistical test: t-test for continuous, z-test for proportions 4. Confidence intervals: Report with estimates, not just p-values 5. Segment analysis: Pre-defined segments only; avoid data dredging 6. Multiple comparisons: Bonferroni or FDR correction if testing many metrics
Early Stopping
Avoid peeking without correction:
- Fixed-horizon testing: Decide duration upfront, don't stop early
- Sequential testing: Use proper sequential boundaries (e.g., Group Sequential, Always Valid P-values)
- Bayesian monitoring: Credible intervals, stop when decisive
Causal Inference
Methods by Context
| Method | Requires | Best For |
|---|---|---|
| Randomized experiment | Control over treatment assignment | Gold standard when feasible |
| Difference-in-differences | Panel data, parallel trends | Policy changes, market rollouts |
| Propensity score matching | Observational, confounders observed | Treatment non-random but explainable |
| Instrumental variables | Valid instrument (affects treatment, not outcome directly) | Endogeneity, omitted variable bias |
| Regression discontinuity | Sharp cutoff in treatment assignment | Scholarship thresholds, age cutoffs |
| Synthetic control | Single treated unit, many control units | Market-level interventions |
Difference-in-Differences Example
import statsmodels.formula.api as smf
# Panel data with treated and post indicators
model = smf.ols('outcome ~ treated * post + entity_fe + time_fe',
data=panel_data).fit()
# Coefficient on treated:post is the ATTPropensity Score Matching
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import NearestNeighbors
# Estimate propensity scores
ps_model = LogisticRegression().fit(X_confounders, treatment)
propensity_scores = ps_model.predict_proba(X_confounders)[:, 1]
# Match treated to control
nn = NearestNeighbors(n_neighbors=1).fit(propensity_scores[treatment==0].reshape(-1, 1))
distances, indices = nn.kneighbors(propensity_scores[treatment==1].reshape(-1, 1))Exploratory Data Analysis (EDA)
Systematic EDA Checklist
1. Structure: Rows, columns, types, missingness pattern 2. Distributions: Histograms, boxplots, summary stats 3. Relationships: Correlation matrix, pairplots, groupby aggregations 4. Anomalies: Outliers, impossible values, data entry errors 5. Temporal: Trends, seasonality, gaps in time series 6. Geographic: Spatial distributions if location data exists
Missing Data Strategy
| Pattern | Strategy |
|---|---|
| MCAR (Missing Completely at Random) | Any imputation valid; listwise deletion unbiased |
| MAR (Missing at Random) | Model-based imputation (MICE, regression) |
| MNAR (Missing Not at Random) | Model the missingness mechanism; be cautious |
Imputation methods:
- Simple: mean, median, mode
- Advanced: KNN imputation, iterative imputer (MICE), MissForest
- Domain: business rule-based (e.g., "no purchase → spend = 0")
Statistical Power & Errors
| Decision ↓ / Reality → | Null True | Alternative True |
|---|---|---|
| Fail to reject null | Correct (1 - α) | Type II error (β) |
| Reject null | Type I error (α) | Correct (1 - β = power) |
Practical significance vs statistical significance:
- p < 0.05 with 1M samples can detect trivial effects
- Always report effect sizes and confidence intervals
- Ask: "Is this difference meaningful for the business?"
Bayesian Basics
When to use Bayesian methods:
- Small sample sizes (priors help regularize)
- Sequential updating (new data refines beliefs)
- Hierarchical structure (users within segments)
- Need full posterior distribution, not just point estimate
Bayesian A/B test:
import pymc as pm
with pm.Model() as model:
p_a = pm.Beta('p_a', alpha=1, beta=1)
p_b = pm.Beta('p_b', alpha=1, beta=1)
obs_a = pm.Binomial('obs_a', n=n_a, p=p_a, observed=conversions_a)
obs_b = pm.Binomial('obs_b', n=n_b, p=p_b, observed=conversions_b)
diff = pm.Deterministic('diff', p_b - p_a)
trace = pm.sample(2000)
# Probability that B is better than A
prob_better = (trace.posterior.diff > 0).mean()Machine Learning Modeling
Algorithm Selection Guide
| Problem Type | Start With | Upgrade To | Avoid |
|---|---|---|---|
| Tabular regression | Ridge/Lasso, Random Forest | XGBoost/LightGBM, TabNet | Deep learning (usually overkill) |
| Tabular classification | Logistic Regression, Random Forest | XGBoost/LightGBM, CatBoost | Deep learning (usually overkill) |
| Time series | ARIMA, Prophet | XGBoost with lags, Temporal Fusion Transformer | Standard cross-validation |
| NLP (text) | TF-IDF + Linear | BERT, LLMs | Bag-of-words for semantic tasks |
| Computer vision | ResNet, EfficientNet | Vision Transformer | Custom architectures unless research |
| Recommendation | Matrix factorization | Two-tower neural, transformers | Cold start without content features |
| Anomaly detection | Isolation Forest, LOF | Autoencoders, VAE | Supervised methods (rarely have labels) |
Feature Engineering Patterns
Numeric Features
# Log transform for skewed distributions
import numpy as np
df['log_revenue'] = np.log1p(df['revenue'])
# Binning for non-linear relationships
df['age_group'] = pd.cut(df['age'], bins=[0, 18, 35, 50, 65, 100])
# Interaction terms
df['price_per_unit'] = df['price'] / df['quantity']Categorical Features
# High cardinality: target encoding (with regularization)
from category_encoders import TargetEncoder
encoder = TargetEncoder(cols=['city'])
# Ordinal: maintain order if exists
df['size_encoded'] = df['size'].map({'S': 1, 'M': 2, 'L': 3})
# One-hot for low cardinality (<10)
pd.get_dummies(df['color'], prefix='color')Temporal Features
# Cyclical encoding for time
df['hour_sin'] = np.sin(2 * np.pi * df['hour'] / 24)
df['hour_cos'] = np.cos(2 * np.pi * df['hour'] / 24)
# Time since event
df['days_since_signup'] = (df['event_date'] - df['signup_date']).dt.daysText Features
# TF-IDF for classical ML
from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer(max_features=10000, ngram_range=(1, 2))
# Embeddings for deep learning
# Use sentence-transformers or LLM APIsCross-Validation Strategies
| Data Type | CV Strategy | Why |
|---|---|---|
| Standard i.i.d. | Stratified K-Fold | Maintains class distribution |
| Time series | Time Series Split | Prevents future leakage |
| Groups/clusters | Group K-Fold | Same group not in train and test |
| Spatial | Spatial cross-validation | Nearby locations correlated |
| Imbalanced | Stratified + SMOTE/undersampling | Balance without leakage |
Time series split example:
from sklearn.model_selection import TimeSeriesSplit
tscv = TimeSeriesSplit(n_splits=5)
for train_idx, test_idx in tscv.split(X):
# train is always before test in time
X_train, X_test = X[train_idx], X[test_idx]Evaluation Metrics
Classification
| Metric | When to Use | Formula |
|---|---|---|
| Accuracy | Balanced classes | (TP + TN) / Total |
| Precision | Cost of false positive is high | TP / (TP + FP) |
| Recall | Cost of false negative is high | TP / (TP + FN) |
| F1 | Balance precision and recall | 2 × (P × R) / (P + R) |
| AUC-ROC | Ranking quality, threshold-independent | Area under ROC curve |
| AUC-PR | Imbalanced classes | Area under precision-recall curve |
| Log loss | Probabilistic evaluation | -Σ(y log(p)) |
Regression
| Metric | When to Use | Formula |
|---|---|---|
| MAE | Robust to outliers | `mean(\ |
| RMSE | Penalize large errors | sqrt(mean((y - ŷ)²)) |
| MAPE | Interpretable % error | `mean(\ |
| R² | Explained variance | 1 - SSR/SST |
| RMSLE | Log-scale targets | sqrt(mean((log(y+1) - log(ŷ+1))²)) |
Hyperparameter Tuning
Search Strategies
| Strategy | When | Cost |
|---|---|---|
| Grid Search | Few parameters, known good ranges | High (exponential) |
| Random Search | Many parameters, wide ranges | Medium |
| Bayesian (Optuna) | Expensive training, need efficiency | Low (smart exploration) |
| Population Based (Ray) | Deep learning, long training | Low (early stopping) |
Optuna example:
import optuna
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
def objective(trial):
n_estimators = trial.suggest_int('n_estimators', 50, 500)
max_depth = trial.suggest_int('max_depth', 3, 20)
min_samples_split = trial.suggest_float('min_samples_split', 0.01, 0.3)
clf = RandomForestClassifier(n_estimators=n_estimators,
max_depth=max_depth,
min_samples_split=min_samples_split)
score = cross_val_score(clf, X, y, cv=5, scoring='f1').mean()
return score
study = optuna.create_study(direction='maximize')
study.optimize(objective, n_trials=100)Model Interpretability
Global Interpretation
- Feature importance: Built-in (tree-based) or permutation importance
- SHAP summary plot: Feature impact distribution
- Partial dependence plots: Feature effect on prediction
Local Interpretation
- SHAP force plot: Why this specific prediction?
- LIME: Local surrogate model explanation
- Counterfactuals: What would change the prediction?
import shap
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_test)
shap.summary_plot(shap_values, X_test)Common Pitfalls
| Pitfall | Detection | Fix |
|---|---|---|
| Data leakage | Feature importance too good to be true | Time-based splits, pipeline all preprocessing |
| Target leakage | Feature correlated with target by construction | Remove post-event features |
| Overfitting | Train >> test performance | Regularization, more data, simpler model |
| Sampling bias | Test distribution ≠ production | Stratify, reweight, or collect better data |
| Temporal leakage | Using future information | Cutoff dates, time-aware validation |
| Group leakage | Same entity in train/test | Group K-Fold |
MLOps & Production
Model Deployment Patterns
Batch Scoring
# Scheduled job (Airflow, cron, cloud scheduler)
def batch_predict(model, input_path, output_path):
df = pd.read_parquet(input_path)
df['prediction'] = model.predict(df[features])
df[['id', 'prediction']].to_parquet(output_path, partition_cols=['date'])Real-Time API
from fastapi import FastAPI
import joblib
app = FastAPI()
model = joblib.load('model.pkl')
@app.post("/predict")
def predict(input_data: dict):
features = preprocess(input_data)
prediction = model.predict([features])[0]
return {"prediction": prediction, "model_version": "1.0.0"}Embedded (Database Native)
-- BigQuery ML example
CREATE OR REPLACE MODEL `project.dataset.model`
OPTIONS(model_type='LOGISTIC_REG')
AS SELECT * FROM `project.dataset.training_data`;
-- Predict in SQL
SELECT * FROM ML.PREDICT(MODEL `project.dataset.model`,
(SELECT * FROM `project.dataset.new_data`));Model Monitoring
What to Monitor
| Layer | Metric | Alert When |
|---|---|---|
| Data drift | PSI (Population Stability Index) > 0.2 | Between training and production features |
| Feature drift | KS test p < 0.01 | Individual feature distribution changes |
| Prediction drift | KL divergence > threshold | Output distribution changes |
| Concept drift | Rolling accuracy decline | >5% drop from baseline |
| Latency | P99 response time | >500ms for real-time APIs |
| Error rate | Failed requests % | >1% |
| Null predictions | % None/NaN outputs | >0.1% |
Drift Detection Example
from scipy.stats import ks_2samp
import numpy as np
def detect_drift(reference, production, threshold=0.01):
"""Returns True if distributions are significantly different"""
statistic, p_value = ks_2samp(reference, production)
return p_value < threshold
# For each feature
for col in features:
if detect_drift(train[col], production[col]):
alert(f"Drift detected in {col}")Shadow Deployment
Run new model alongside production without serving its predictions:
- Log predictions from both models
- Compare offline metrics
- Switch traffic when new model is validated
Feature Stores
When to Use
- Same features needed by multiple models
- Complex feature engineering (streaming aggregations)
- Need point-in-time correctness (prevent leakage)
Architecture
Raw Data → Feature Pipelines → Feature Store → Models
(online + offline)| Store | Online Latency | Offline | Examples |
|---|---|---|---|
| Feast | Redis/DynamoDB | BigQuery/Snowflake | Open source |
| Tecton | Low latency | Spark | Enterprise |
| SageMaker Feature Store | <10ms | S3 | AWS native |
Point-in-Time Correctness
# Critical: feature values as they were at prediction time
# NOT as they are now
features_at_time = feature_store.get_features(
entity_ids=['user_123'],
timestamp='2024-01-15T10:00:00Z' # NOT now()
)Model Versioning & Registry
MLflow Tracking
import mlflow
mlflow.set_experiment("churn_prediction")
with mlflow.start_run():
mlflow.log_params({"n_estimators": 100, "max_depth": 6})
mlflow.log_metrics({"f1": 0.85, "auc": 0.92})
mlflow.sklearn.log_model(model, "model")
mlflow.set_tag("version", "v1.2.0")Model Registry Stages
1. Staging: Candidate model under evaluation 2. Production: Currently serving traffic 3. Archived: Retired, kept for audit
CI/CD for ML
Pipeline Stages
Code commit → Unit tests → Integration tests → Train model → Evaluate → Register → DeployKey differences from software CI/CD:
- Model training is non-deterministic (set seeds, log everything)
- Evaluation needs hold-out data (not just unit tests)
- Deployment may require data validation, not just code validation
- Rollback means reverting to previous model artifact
Testing Strategy
| Test Type | What | When |
|---|---|---|
| Unit tests | Feature transforms, preprocessing | Every commit |
| Data tests | Schema, nulls, distributions | Before training |
| Model tests | Performance > baseline on hold-out | After training |
| Integration tests | End-to-end inference pipeline | Before deploy |
| Canary tests | A/B production validation | After deploy |
Git-Based Workflows
Git-flow for ML:
main: Production model + codedevelop: Integration branchexperiment/<name>: Model experiments (may not merge)feature/<name>: Code features (merge to develop)
Model promotion via PR:
- Training run triggered on PR
- Evaluation metrics posted as PR comment
- Human review + automated gates → merge → deploy
Retraining Strategy
| Trigger | When | Implementation |
|---|---|---|
| Scheduled | Weekly/monthly | Cron job retrains on latest data |
| Performance-based | Accuracy < threshold | Monitor metric, trigger retrain |
| Data volume | N new labeled samples | Count new labels, threshold trigger |
| Manual | Ad-hoc needs | One-off training job |
Retraining checklist:
- [ ] New data passes quality checks
- [ ] Feature pipeline unchanged (or updated and tested)
- [ ] New model beats current production on hold-out
- [ ] A/B test or shadow mode before full cutover
- [ ] Update model metadata and documentation
Cost Optimization
| Technique | Savings |
|---|---|
| Spot/preemptible instances for training | 60-90% |
| Auto-scaling inference | Pay for actual load |
| Model distillation | Smaller model, faster inference |
| Feature caching | Reduce repeated computation |
| Early stopping in HPO | Don't train poor configurations to completion |
Tools & Frameworks
Environment Setup
Python Environment
# Recommended: uv or conda
uv venv .venv
source .venv/bin/activate
# Core stack
uv pip install pandas polars numpy scikit-learn xgboost
# Optional by use case
uv pip install torch transformers # deep learning
uv pip install statsmodels scipy # statistics
uv pip install mlflow optuna # experiment tracking + HPO
uv pip install fastapi uvicorn # API serving
uv pip install shap lime # interpretabilityR Environment
install.packages(c("tidyverse", "caret", "randomForest", "xgboost"))
install.packages(c("broom", "infer", "rsample")) # tidy statsLibrary Comparison
Data Manipulation
| Library | Strengths | Weaknesses | When to Use |
|---|---|---|---|
| pandas | Ubiquitous, rich ecosystem | Slow on large data | <10M rows, exploration |
| Polars | Fast, lazy evaluation, memory efficient | Newer, smaller ecosystem | Large data, production |
| DuckDB | SQL engine, in-process | Not a dataframe library | SQL-heavy workflows |
| PySpark | Distributed, big data | Heavy overhead | >100M rows, cluster |
| data.table (R) | Fast, concise syntax | R-only | R users, large data |
Machine Learning
| Library | Algorithms | Best For |
|---|---|---|
| scikit-learn | Comprehensive classical ML | Baselines, preprocessing, pipelines |
| XGBoost | Gradient boosted trees | Tabular data, competitions |
| LightGBM | Faster XGBoost alternative | Large tabular datasets |
| CatBoost | Categorical handling | Datasets with many categoricals |
| PyTorch | Deep learning, flexible | Research, custom architectures |
| TensorFlow/Keras | Deep learning, production | Google Cloud, TF Serving |
| Statsmodels | Statistical models | Inference, regression diagnostics |
Experiment Tracking
| Tool | Open Source | Best Feature | Limitation |
|---|---|---|---|
| MLflow | Yes | Model registry + tracking | Self-hosted complexity |
| Weights & Biases | No | Visualization, collaboration | Cost at scale |
| Neptune | No | Fast UI, model comparison | Cost |
| DVC | Yes | Data versioning, git-like | CLI-heavy |
| TensorBoard | Yes | Free with TensorFlow | TF-centric |
Code Patterns
Reproducible Experiment
import random
import numpy as np
from sklearn.model_selection import cross_val_score
def set_seed(seed=42):
random.seed(seed)
np.random.seed(seed)
# Add framework-specific seeds
# torch.manual_seed(seed)
# tf.random.set_seed(seed)
set_seed(42)
# Log everything
config = {
"model": "XGBClassifier",
"n_estimators": 100,
"max_depth": 6,
"seed": 42
}
# mlflow.log_params(config)
model = XGBClassifier(**config)
scores = cross_val_score(model, X, y, cv=5)
# mlflow.log_metric("cv_f1", scores.mean())Pipeline Pattern
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
preprocessor = ColumnTransformer([
('num', StandardScaler(), numeric_features),
('cat', OneHotEncoder(handle_unknown='ignore'), categorical_features)
])
pipeline = Pipeline([
('preprocess', preprocessor),
('model', XGBClassifier())
])
# Prevents leakage: preprocessing fit only on training fold
pipeline.fit(X_train, y_train)
pipeline.score(X_test, y_test)Time Series Split
from sklearn.model_selection import TimeSeriesSplit
from sklearn.metrics import mean_squared_error
tscv = TimeSeriesSplit(n_splits=5)
scores = []
for train_idx, test_idx in tscv.split(X):
X_train, X_test = X.iloc[train_idx], X.iloc[test_idx]
y_train, y_test = y.iloc[train_idx], y.iloc[test_idx]
model.fit(X_train, y_train)
preds = model.predict(X_test)
scores.append(mean_squared_error(y_test, preds))Cloud ML Services
| Service | Provider | Best For |
|---|---|---|
| SageMaker | AWS | Full ML lifecycle, notebook instances |
| Vertex AI | GCP | AutoML, model registry, pipelines |
| Azure ML | Azure | Enterprise, MLOps integration |
| Databricks | Multi-cloud | Spark + ML + collaborative notebooks |
Performance Tips
Pandas:
- Use
categorydtype for low-cardinality strings - Vectorize with
.apply()only as last resort - Use
.loc[]for assignment to avoid SettingWithCopy - Chunk large files:
pd.read_csv(file, chunksize=100000)
scikit-learn:
- Use
n_jobs=-1for parallelizable operations - Prefer
jobliboverpicklefor model serialization - Use
Pipelineto prevent data leakage
XGBoost/LightGBM:
- Use
early_stopping_roundsto prevent overfitting - Set
tree_method='hist'for large datasets - Use
feature_nameandfeature_typesfor interpretability
Common Errors & Fixes
| Error | Cause | Fix |
|---|---|---|
ValueError: Input contains NaN | Missing values in features | Impute or drop before fitting |
DataConversionWarning | Wrong dtype (e.g., object instead of numeric) | Convert types explicitly |
ConvergenceWarning | Model didn't converge | Increase max_iter, scale features |
| MemoryError with large data | Loading everything into RAM | Use generators, sample, or distributed |
| Different train/test encodings | Fit transform on train, only transform on test | Use Pipeline |