Gradient LabStart the lesson

Lessons › Chapter 7: Unsupervised learning

Anomaly detection

Gather lots of everyday data: here, ordinary transactions. Most of it clumps together. The dashed ring marks “normal”.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

A brand-new scam

A new kind of scam appears that none of their labeled examples cover yet.

Concept

Learn what normal looks like

Gather lots of everyday data: here, ordinary transactions. Most of it clumps together. The dashed ring marks “normal”.

Build

Score each new point

When something new arrives, measure how unusual it is, for example how far it sits from the normal clump. One new point lands inside, another far outside.

Key idea

Flag the unusual

If the score passes a threshold, the point is flagged as an anomaly for a person to check. Most of the time nothing is flagged, which is exactly what you want.

Insight

Why not just train a classifier?

Real problems, like fraud or machine faults, are rare and keep changing shape. You may have almost no labeled examples of them. Learning “normal” well lets you catch odd things you’ve never seen before.

Real life

In real life: “Was this you?”

Your card is used near home most days. Then a large purchase appears in another country at 3 am. It sits far from your normal pattern, so the bank asks “Was this you?” before letting it through. Factories use the same idea to spot machines about to fail.

Quick check: Why is learning “normal” useful for catching fraud?

You rarely have many labeled fraud cases, but you have lots of normal behavior to learn from.

Pseudocode

learn what “normal” looks like from lots of everyday data
for each new point:
    score = how unusual it is (for example, distance from normal)
    if score > threshold:
        flag it for a person to check

Key terms

anomaly
A data point that is unusual compared with the rest.

Build it: Spot fraud with anomaly detection (25 min, runs in your browser)

See the project