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

Explainable Intrusion Detection

Projects · Project Advanced

Description

Add an explanation layer (permutation importance and Shapley) to an IDS classifier.

The project uses synthetic data or licensed public datasets after checking their terms; it involves no attacks and no opening of malicious files or links.

Goals

  • Global and local explanation
  • Assess explanation stability

Requirements

  • Python or the workbench.

Data

Synthetic or a licensed IDS set.

Suggested datasets

Suggested algorithms

Implementation steps

  1. Train RF
  2. Compute permutation importance
  3. Explain two alert samples
  4. Change the baseline and watch stability

Code

p-xai-ids.py
# Use the lab’s SHAP-style experiment (mal.explain) for an in-browser version; this sketch shows permutation importance only.
# Educational sketch on SYNTHETIC data (no download, no real traffic). Requires: numpy, scikit-learn
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, roc_auc_score, average_precision_score
rng = 7
from sklearn.datasets import make_classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.inspection import permutation_importance
X, y = make_classification(n_samples=2000, n_features=8, n_informative=4, weights=[0.8, 0.2], random_state=rng)
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.3, stratify=y, random_state=rng)
m = RandomForestClassifier(random_state=rng).fit(Xtr, ytr)
print(permutation_importance(m, Xte, yte, n_repeats=10, random_state=rng).importances_mean.round(3))

Expected results and how to read them

Expected results (qualitative, not achieved numbers): Importances will vary with baseline and model.

Challenges

  • An explanation is not causality

Extensions

Test agreement between two explanation methods.

Related experiments

Related labs

References

  1. Arp, Quiring, Pendlebury, Warnecke, Pierazzi, Wressnegger, Cavallaro, Rieck (2024). Pitfalls in Machine Learning for Computer Security. Communications of the ACM 67(11), pp. 104-112. doi:10.1145/3643456