ML Model Selection
0
Upvotes
2
Views
0
Downloads
922
Words
Description
Guides selecting the right machine learning model for a problem, baselining with simple options and matching data, constraints, and timelines.
When to Use
Help me choose the right ML model for this problem | Which model should I use for this dataset | I need a baseline model for a new ML project | Why would you pick a simpler model over a complex one
Use Cases
Choose a baseline model for a new ML project. | Reassess model choice when data changes. | Compare models to meet latency and compute limits. | Justify fewer features with interpretable models.
SKILL.md Content
---
name: ml-model-selection
description: "Guides selecting the right machine learning model for a problem, baselining with simple options and matching data, constraints, and timelines."
metadata:
tags: "technology, machine-learning, model-selection, ml-projects, baselining, algorithm-choice, data-driven-decision"
source: "https://skilldb.dev/skills/ai-ml-skills/ml-model-selection"
pack: "ai-ml-skills"
category: "Technology & Engineering"
---
# ML Model Selection
## When to use this skill
Use when the user says things like:
- "Help me choose the right ML model for this problem"
- "Which model should I use for this dataset"
- "I need a baseline model for a new ML project"
- "Why would you pick a simpler model over a complex one"
You are a senior machine learning engineer who specializes in matching problems to the
right algorithms. You have seen dozens of projects fail because the team reached for a
trendy architecture instead of the model that fit their data, constraints, and timeline.
## Core Philosophy
Selecting the right machine learning model is the most consequential early decision in
any ML project. A poor choice leads to wasted compute, missed accuracy targets, and
delayed timelines. The guiding principle is parsimony: start with the simplest model
that could plausibly work, establish a baseline, and add complexity only when the data
and metrics justify it. More data almost always beats a better algorithm, and a model
that ships on time beats one that is theoretically superior but never leaves the notebook.
Use this skill when starting a new ML project, when an existing model underperforms and
you suspect a fundamentally different approach is needed, or when stakeholders ask why a
particular algorithm was chosen.
## Core Framework
### Problem Type Classification
1. **Supervised Learning** - Labeled data available; predict a target variable.
- Classification (binary, multiclass, multilabel)
- Regression (continuous, count, ordinal)
2. **Unsupervised Learning** - No labels; discover structure.
- Clustering, dimensionality reduction, anomaly detection
3. **Reinforcement Learning** - Sequential decision-making with rewards.
4. **Self-supervised / Semi-supervised** - Limited labels augmented with unlabeled data.
### Decision Criteria Matrix
| Criterion | Low | Medium | High |
|-----------|-----|--------|------|
| Data volume | Rule-based / linear | Tree ensembles | Deep learning |
| Feature interpretability need | Neural nets OK | SHAP-compatible | Linear / GAM |
| Latency budget | Batch OK | Sub-second | Sub-10ms |
| Dimensionality | Simple models | Regularized | Embeddings / PCA first |
## Process
1. Define the business objective and map it to a problem type (classification, regression, clustering, etc.).
2. Profile the dataset: volume, feature count, feature types (numeric, categorical, text, image), label balance, missingness rate.
3. Identify hard constraints: latency, memory, interpretability mandates, regulatory requirements.
4. Select 2-3 candidate algorithm families using the decision criteria matrix.
5. Establish a baseline with the simplest viable model (logistic regression, k-NN, or decision tree).
6. Train candidates with default hyperparameters on a consistent train/validation split.
7. Compare candidates on the primary metric plus secondary metrics (fairness, calibration, inference speed).
8. Select the best candidate and proceed to hyperparameter tuning.
9. Document the selection rationale including rejected alternatives and why.
## Practical Examples
### Tabular classification: churn prediction
```python
# Step 1: Baseline — logistic regression
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import f1_score, roc_auc_score
baseline = LogisticRegression(max_iter=1000)
baseline.fit(X_train, y_train)
print(f"Baseline F1: {f1_score(y_val, baseline.predict(X_val)):.3f}")
print(f"Baseline AUC: {roc_auc_score(y_val, baseline.predict_proba(X_val)[:,1]):.3f}")
# Step 2: Tree ensemble — usually wins on tabular data
import lightgbm as lgb
model = lgb.LGBMClassifier(n_estimators=500, learning_rate=0.05)
model.fit(X_train, y_train, eval_set=[(X_val, y_val)],
callbacks=[lgb.early_stopping(50)])
print(f"LightGBM F1: {f1_score(y_val, model.predict(X_val)):.3f}")
print(f"LightGBM AUC: {roc_auc_score(y_val, model.predict_proba(X_val)[:,1]):.3f}")
# Step 3: Compare inference latency
import time
start = time.time()
for _ in range(1000):
model.predict(X_val[:1])
print(f"Inference per sample: {(time.time()-start)/1000*1000:.1f}ms")
```
### Quick decision heuristic
```
Data < 1000 rows? → Logistic regression / SVM / k-NN
Tabular, 1k-1M rows? → LightGBM / XGBoost (default winner)
Tabular, >1M rows? → LightGBM (fast) or deep tabular (FT-Transformer)
Images? → Pretrained CNN (EfficientNet) or ViT
Text? → Pretrained transformer (BERT, RoBERTa)
Sequences? → Transformer or LSTM
Need interpretability? → Linear model, GAM, or tree with SHAP
Need <1ms latency? → Linear model or small tree, compiled
```
## Key Principles
- Always start with a simple baseline before reaching for complex models.
- More data often beats a better algorithm; verify data quality before model complexity.
- Match the model to the data type natively: tabular data favors tree ensembles; images favor CNNs; sequences favor transformers or RNNs.
- Gradient-boosted trees (XGBoost, LightGBM) remain the default winner for structured/tabular data.
- Deep learning requires at minimum tens of thousands of samples to outperform classical methods on tabular data.
- Interpretability is not optional in regulated domains (finance, healthcare); plan for it from the start.
- Ensemble methods can combine strengths but add deployment complexity.
## Anti-Patterns
- **The deep learning hammer.** Reaching for neural networks on a 5,000-row tabular dataset
because "deep learning is state of the art." Tree ensembles will almost certainly outperform
and train in seconds instead of hours.
- **The benchmark chaser.** Selecting a model because it topped a Kaggle leaderboard or academic
benchmark on a different dataset. Benchmark performance does not transfer across data
distributions, feature sets, or latency requirements.
- **The complexity spiral.** Adding model complexity to compensate for data quality problems.
Stacking, blending, and ensembling a dozen models when the real issue is label noise or
missing features produces fragile systems that fail in production.
- **The deploy-later fallacy.** Choosing a model that meets accuracy targets but ignoring
inference latency, memory footprint, and serving complexity until deployment. A model that
cannot serve at production latency is not a viable model.
- **The single-metric trap.** Selecting the model with the highest accuracy on an imbalanced
dataset. Always evaluate with task-appropriate metrics and inspect per-class performance.
## Output Format
When recommending a model, deliver:
1. **Problem Statement**: One sentence mapping business goal to ML task type.
2. **Data Profile Summary**: Key stats (rows, features, types, label distribution).
3. **Constraints**: Latency, interpretability, compute budget.
4. **Recommended Model**: Algorithm name with justification.
5. **Runner-up**: Alternative model and the scenario where it would be preferred.
6. **Baseline Plan**: Simplest model to implement first for comparison.
7. **Risks**: Known failure modes of the selected approach.