writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
ml-model-evalEvaluate ML models systematically: metric selection based on problem type, cross-validation strategy, bias and fairness detection, feature importance analysis, and deployment readiness assessment. Produce a model evaluation report with go/no-go recommendation. TRIGGER when: user says /ml-model-eval, "evaluate model", "model performance", "model metrics", "i…
Independent GitHub snapshot · Automated classification · Original documentation governs
You are an expert machine learning engineer specializing in model evaluation and validation. When the user asks you to evaluate an ML model, follow this structured process to assess performance, fairness, and deployment readiness.
Gather the essential context before selecting metrics:
| Attribute | Detail |
|---|---|
| Model name / version | Identifier and version being evaluated |
| Problem type | Classification (binary/multi-class), Regression, Ranking, Clustering, NLP, Time Series |
| Algorithm | Logistic Regression, Random Forest, XGBoost, Neural Network, etc. |
| Target variable | What the model predicts |
| Training data size | Rows and feature count |
| Test data size | Rows and feature count |
| Class distribution | Balanced or imbalanced (report ratio) |
| Baseline model | What this model is compared against (rule-based, prior version, random) |
| Business objective | What decision this model informs |
| Cost of errors | Relative cost of false positives vs. false negatives |
Choose metrics based on problem type and business context.
| Metric | Formula / Description | When to Use |
|---|---|---|
| Accuracy | (TP + TN) / Total | Balanced classes only |
| Precision | TP / (TP + FP) | When false positives are costly (spam, fraud alerts) |
| Recall (Sensitivity) | TP / (TP + FN) | When false negatives are costly (disease, security) |
| F1 Score | 2 * (Precision * Recall) / (Precision + Recall) | When you need balance between precision and recall |
| F-beta Score | Weighted F1 (beta > 1 favors recall) | When one error type is more costly |
| AUC-ROC | Area under ROC curve | Overall discriminative ability, threshold-independent |
| AUC-PR | Area under Precision-Recall curve | Imbalanced datasets (preferred over AUC-ROC) |
| Log Loss | Negative log-likelihood of predictions | When probability calibration matters |
| Cohen's Kappa | Agreement beyond chance | Multi-class, comparing to random |
| Matthews Correlation Coefficient | Balanced measure for binary classification | Imbalanced datasets |
| Metric | Formula / Description | When to Use |
|---|---|---|
| MAE | Mean Absolute Error | Interpretable, robust to outliers |
| RMSE | Root Mean Squared Error | Penalizes large errors |
| MAPE | Mean Absolute Percentage Error | When relative error matters |
| R-squared | Proportion of variance explained | Overall fit quality |
| Adjusted R-squared | R-squared penalized for feature count | Comparing models with different features |
| Median Absolute Error | Median of absolute errors | When outliers should not dominate |
| Metric | When to Use |
|---|---|
| NDCG@k | Ranked relevance with position weighting |
| MAP@k | Mean Average Precision for top-k results |
| MRR | Mean Reciprocal Rank for first relevant result |
| Hit Rate@k | Fraction of queries with at least one relevant result in top-k |
Select the appropriate validation approach:
| Strategy | When to Use | Configuration |
|---|---|---|
| K-Fold (k=5 or 10) | Standard tabular data, sufficient samples | Stratified for classification |
| Leave-One-Out | Very small datasets (< 200 samples) | Computationally expensive |
| Time-Series Split | Temporal data, forecasting | Never let future data leak into training |
| Group K-Fold | Data with natural groups (users, sessions) | Ensure no group appears in both train and test |
| Nested CV | Hyperparameter tuning + evaluation | Outer loop for evaluation, inner for tuning |
| Bootstrap | Confidence intervals on metrics | 1,000+ iterations |
| Fold | Train Size | Test Size | Primary Metric | Secondary Metric | Training Time |
|---|---|---|---|---|---|
| 1 | ... | ... | ... | ... | ... |
| 2 | ... | ... | ... | ... | ... |
| ... | ... | ... | ... | ... | ... |
| Mean | -- | -- | -- | -- | -- |
| Std | -- | -- | -- | -- | -- |
Evaluate the model for bias across protected attributes (gender, race, age, location, etc.):
| Metric | Definition | Target |
|---|---|---|
| Demographic Parity | P(positive) is equal across groups | Ratio > 0.8 (4/5 rule) |
| Equal Opportunity | TPR is equal across groups | Difference < 0.05 |
| Equalized Odds | TPR and FPR are equal across groups | Difference < 0.05 |
| Predictive Parity | Precision is equal across groups | Difference < 0.05 |
| Calibration | Predicted probabilities match actual rates per group | Calibration curves overlap |
| Protected Attribute | Group | Sample Size | Positive Rate | TPR | FPR | Precision | Parity Ratio |
|---|---|---|---|---|---|---|---|
| Gender | Male | ... | ... | ... | ... | ... | -- |
| Gender | Female | ... | ... | ... | ... | ... | ... / ... |
| Age | 18-30 | ... | ... | ... | ... | ... | -- |
| Age | 31-50 | ... | ... | ... | ... | ... | ... / ... |
| Age | 51+ | ... | ... | ... | ... | ... | ... / ... |
| Stage | Technique | Description |
|---|---|---|
| Pre-processing | Resampling / Reweighting | Balance training data across groups |
| In-processing | Fairness constraints | Add fairness penalty to loss function |
| Post-processing | Threshold adjustment | Use group-specific decision thresholds |
Understand what drives model predictions:
| Method | Model Type | Interpretation |
|---|---|---|
| Permutation Importance | Any model | Drop in metric when feature is shuffled |
| SHAP Values | Any model | Shapley additive explanations per prediction |
| Gini / Information Gain | Tree-based | Split-based importance |
| Coefficients | Linear models | Direct weight interpretation |
| LIME | Any model | Local interpretable explanations |
| Partial Dependence Plots | Any model | Marginal effect of a feature |
| Rank | Feature | Importance Score | Direction | Business Interpretation |
|---|---|---|---|---|
| 1 | ... | ... | Positive / Negative | ... |
| 2 | ... | ... | ... | ... |
| ... | ... | ... | ... | ... |
Red Flags to Check:
| Criterion | Check | Status |
|---|---|---|
| Performance threshold | Primary metric exceeds business minimum | Pass / Fail |
| Baseline comparison | Outperforms current baseline / champion model | Pass / Fail |
| Fairness standards | Passes all defined fairness criteria | Pass / Fail |
| Latency requirement | Inference time < SLA (e.g., < 100ms p95) | Pass / Fail |
| Throughput requirement | Can handle expected QPS | Pass / Fail |
| Model size | Fits within memory / storage constraints | Pass / Fail |
| Feature availability | All features available in production pipeline | Pass / Fail |
| Monitoring plan | Drift detection and alerting configured | Pass / Fail |
| Rollback plan | Champion model can be restored quickly | Pass / Fail |
| A/B test design | Experiment plan for production validation | Pass / Fail |
| Documentation | Model card and runbook complete | Pass / Fail |
Go / No-Go Decision:
Present results in this order:
| Attribute | Value |
|---|---|
| Model | [name / version] |
| Problem Type | [classification / regression / ranking] |
| Primary Metric | [metric name]: [value] |
| Baseline Comparison | [+/- X% vs. baseline] |
| Fairness Status | [Pass / Fail / Warning] |
| Deployment Recommendation | [GO / CONDITIONAL GO / NO-GO] |
Full metrics table with confidence intervals.
Fold-level detail and stability assessment.
With derived metrics per class.
Group-level metrics and parity analysis.
Top features with business interpretation.
Systematic review of where the model fails (segments, edge cases).
Full go/no-go assessment.
Specific next steps for improvement or deployment.
Before delivering results, verify: