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

K-means (distance to centroid)

Algorithm Library · Algorithm Unsupervised Learning Runs in the browser

The idea

Clusters data into k groups; points far from the nearest centroid are treated as anomalous.

The problem it addresses

Anomaly detection when normal behaviour has a few modes.

Data it needs

Scaled data.

Equations

\operatorname{score}(x)=\min_j\lVert x-\mu_j\rVert_2

Steps

  1. Start from random centroids
  2. Assign each point to its nearest centroid
  3. Recompute the centroids
  4. Record the distance as the score

Pseudocode

kmeans-distance.txt
repeat: assign = argmin_j ||x-mu_j||; mu_j = mean(X[assign==j])
score = min_j ||x-mu_j||

Strengths

  • Simple and fast

Limitations

  • Assumes spherical clusters
  • Sensitive to initialisation

Uses in cybersecurity

  • Anomaly baseline

Common pitfalls

  • The choice of k changes results sharply; try several.

Suggested datasets

Related experiments

References

  1. Chandola, Banerjee, Kumar (2009). Anomaly detection: A survey. ACM Computing Surveys 41(3), pp. 1-58. doi:10.1145/1541880.1541882