Skip to content
Back to skills

Model Evaluation

ASecurity

Guides model evaluation with threshold selection and subgroup fairness analysis; use when evaluating a trained model, comparing model versions, or performing fairness analysis.

  • 19 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 19, 2026
ai-agentspython

Security analysis

A100/100

Scanned October 19, 2026

npx -y skills add sawrus/agent-guides --skill model-evaluation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Model Evaluation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Model Evaluation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sawrus-model-evaluation/badge)](https://www.skillsdirectory.com/skills/sawrus-model-evaluation)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: model-evaluation
description: "Guides model evaluation with threshold selection and subgroup fairness analysis; use when evaluating a trained model, comparing model versions, or performing fairness analysis."
---

# Skill: Model Evaluation

## When to load

When evaluating a trained model, comparing versions, or performing fairness analysis.

## Threshold Selection

```python
def select_optimal_threshold(y_true, y_prob, business_objective: str):
    """
    business_objective:
    - 'max_f1': balanced precision/recall
    - 'high_precision': minimize false positives (fraud)
    - 'high_recall': minimize false negatives (screening)
    """
    precisions, recalls, thresholds = precision_recall_curve(y_true, y_prob)
    if business_objective == 'max_f1':
        f1_scores = 2 * (precisions * recalls) / (precisions + recalls + 1e-8)
        return thresholds[np.argmax(f1_scores)]
```

## Subgroup Fairness Analysis (Required for People-Affecting Models)

```python
def evaluate_fairness(y_true, y_pred, sensitive_attribute):
    groups = sensitive_attribute.unique()
    results = {g: {
        "n": (sensitive_attribute == g).sum(),
        "positive_rate": y_pred[sensitive_attribute == g].mean(),
        "tpr": recall_score(y_true[sensitive_attribute == g], y_pred[sensitive_attribute == g]),
    } for g in groups}

    pos_rates = [r["positive_rate"] for r in results.values()]
    dp_diff = max(pos_rates) - min(pos_rates)

    if dp_diff > 0.1:
        logger.warning(f"Demographic parity difference {dp_diff:.3f} exceeds 0.1 threshold")
    return results, dp_diff
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.