EZ LearnEZ Learn
Courses
EZ Board
Dashboard
All articles
ml-for-cyber-securitymlcsuebararity-scoring

Rarity-Based Scoring: A Simpler Alternative

Not every anomaly detector needs to be a trained model. UEBA products commonly score an event by how rare it is for this specific user, not how far it sits from a fitted mathematical boundary.

Ashish Revar25 October 20265 min read

Not every anomaly detector needs to be a trained model. User and Entity Behavior Analytics (UEBA) products commonly use a much simpler idea alongside, or instead of, the methods above: score an event by how rare it is for the specific user or host involved, not how far it sits from a fitted boundary.

  1. For each user or host, maintain a historical count of how often each distinct activity (a privilege used, a host contacted, a file accessed) has occurred.
  2. For a new event, compute its rarity: how small a fraction of this entity's history this specific activity represents.
  3. Map rarity to a score, typically with sharply increasing severity as rarity approaches zero (an activity never seen before for this entity scores far higher than one seen occasionally).
  4. Combine the rarity score with other signals (time of day, peer-group comparison) before alerting, since rarity alone produces many false positives for any user whose role is simply varied.

rarity_scorer.py

from collections import Counter

def rarity_score(entity_history: Counter, activity: str) -> float:
    total = sum(entity_history.values())
    if total == 0:
        return 1.0
    frequency = entity_history[activity] / total
    return 1.0 - frequency     # closer to 1.0 = rarer = more suspicious

# example: an admin who has used sudo 400 times, but never before
# touched this specific, sensitive configuration file
history = Counter({"sudo": 400, "ssh": 120, "edit_config_a": 3})
print(rarity_score(history, "edit_config_b"))   # never seen: scores 1.0
print(rarity_score(history, "sudo"))            # routine: scores low

Caution: Rarity Is Cheap, but Noisy

A rarity scorer needs no training data, no feature engineering, and no model maintenance, which is exactly why it is so widely deployed. Its weakness is equally simple: anything a user does for the first time scores as maximally suspicious, including entirely legitimate new activity (a new project, a new tool, a role change), so rarity scoring is almost always paired with a second signal, exactly as the algorithm box above recommends, rather than used to alert on its own.

Case study: Unsupervised Detection in Commercial Network Defence

Several commercial network detection and response products, publicly including Darktrace, describe their core approach as building an unsupervised statistical model of what is "normal" for a specific network, then flagging activity that deviates from that learned baseline, explicitly without relying on signatures of known attacks. The approach's strength is exactly the one this unit has built: it can flag a genuinely novel attack technique the day it first appears, because novelty itself is the signal, not a match against a known pattern. Its weakness is the same one every unsupervised method shares: a baseline learned during a quiet period can itself be wrong, and a slow, patient attacker who changes behaviour gradually can shift the learned "normal" without ever triggering a large deviation.

Try it yourself: Find the Right eps for DBSCAN

Run DBSCAN on the same traffic dataset for eps values of 0.3, 0.6, and 1.0, holding min_samples fixed. Count the number of clusters and the number of points labelled as outliers at each setting. You will see directly why DBSCAN's parameters need to be tuned per dataset, not copied from a tutorial.

Related to this topic

Continue learning

Reference material

eBook

ML for Cyber Security eBook

v1.0

Open resource

Cheatsheet

ML for Cyber Security Cheatsheet

v1.0

Open resource

MCQ Bank

ML for Cyber Security MCQ Bank

v1.0

Open resource

Question Bank

ML for Cyber Security Question Bank

v1.0

Open resource

Discussion

Loading comments…
More articlesTest your knowledge
EZ MentorAI · Free

Rarity-Based Scoring: A Simpler Alternative

Hi! I'm EZ Mentor

Your AI tutor for
Rarity-Based Scoring: A Simpler Alternative

Sign in to ask, it's free.

EZ Mentor is AI-powered · Answers may not be perfect · 10 free questions / day

EZ Learn

Structured learning across Reverse Engineering, Cloud Security and Research Methodology, plus games and practice tools. Free, and open to anyone.

Learn

  • Courses
  • EZ Articles
  • EZ Watch
  • EZ Bytes
  • EZ Talks
  • Community

Library & Exams

  • All Resources
  • eBooks & PDFs
  • Question Banks
  • Cheatsheets
  • All Exams
  • EZ Board

EZ Arena

  • EZ Games
  • Byte Rush
  • Firewall Defence
  • 3D Case Files
  • Live Quiz
  • ML Challenges

EZ Cyber Hygiene

  • Hygiene Journey
  • Cyber Safety Check
  • दिशा - Hygiene
  • सजग - Awareness
  • अभ्यास - Practice
  • Scammed? Call 1930

Platform

  • About
  • Contact
  • Events
  • Verify Certificate
  • Terms of Use
  • Disclaimer

© 2026 EZ Learn by EpochZero. Educational content for learning purposes.

Platform Lead: Ashish Revar