AI Cybersecurity Lab

Intrusion and anomaly detection, malware analysis, threat intelligence, phishing, security logs and incident response: defensive experiments that really compute in your browser on synthetic data, with algorithms, datasets, projects and quizzes.

28interactive experiments

Handling class imbalance

Algorithm Library · Algorithm Rule-based and statistical (non-learning; extra to the eight) Explained only

This algorithm is explained only: this version has no in-browser training experiment for it and shows no performance numbers.

The idea

Attacks are usually rare; handle it with recall, PR-AUC, re-weighting and threshold tuning instead of accuracy.

The problem it addresses

Avoiding “everything is normal” models with 99% accuracy.

Data it needs

Any labelled data.

Equations

\text{precision}=\tfrac{TP}{TP+FP},\ \text{recall}=\tfrac{TP}{TP+FN}

Steps

  1. Compute the class ratio
  2. Pick suitable metrics
  3. Tune the threshold

Pseudocode

class-imbalance.txt
# يُدرَّس مفهومياً

Strengths

  • More honest evaluation

Limitations

  • Does not fix scarcity of real examples

Uses in cybersecurity

  • Every detection task

Common pitfalls

  • ROC-AUC can look high while operational precision is poor when attacks are rare.

Suggested datasets

Related experiments

References

  1. Saito, Rehmsmeier (2015). The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets. PLOS ONE 10(3), e0118432. doi:10.1371/journal.pone.0118432
  2. Davis, Goadrich (2006). The relationship between Precision-Recall and ROC curves. ICML 2006, pp. 233-240. doi:10.1145/1143844.1143874