Recall is the proportion of actual positive observations that a detection system correctly identifies: true positives divided by true positives plus false negatives. section 3.8.2
Use recall to interpret anomaly-detection coverage:
- High recall means the system misses few actual anomalies, but it may label many normal points incorrectly. section 5.8 section 8.8.3
- Reducing a prediction interval generally increases recall while decreasing precision; prioritize recall when missing anomalies is more costly. section 3.8.2
- Compare recall with precision and F1 score rather than treating it as a complete performance assessment. section 3.8.2
Anomaly-detection evaluation
A detector that identifies three of four true anomalies achieves 0.75 recall, even though only 38% of its flagged points are correct. section 3.8.2
Listing 3.26 Function to evaluate anomaly detection
def evaluate_anomaly_detection(df, preds_col, actual_col):
tp = ((df[preds_col] == 1) & (df[actual_col] == 1)).sum()
tn = ((df[preds_col] == 0) & (df[actual_col] == 0)).sum()
fp = ((df[preds_col] == 1) & (df[actual_col] == 0)).sum()
fn = ((df[preds_col] == 0) & (df[actual_col] == 1)).sum()
precision = tp / (tp + fp) if (tp + fp) != 0 else 0
recall = tp / (tp + fn) if (tp + fn) != 0 else 0
f1_score = 2 * (precision * recall) / (precision + recall) if
➥(precision + recall) != 0 else 0
return precision, recall, f1_score
Inspect the Python implementation that counts true positives and false negatives before calculating recall. section 3.8.2























