Gradient LabSign up free

Cheat sheets › Chapter 7

Unsupervised learning cheat sheet

Find structure in data that has no labels. Every lesson in one page: the key idea, the pseudocode and the terms.

k-means clustering

Here are 24 customers placed by how they shop. Nobody has told us any groups. Can the computer find natural clusters on its own?

k = 3
centers = pick 3 random spots
repeat until nothing changes:
    each point joins its nearest center
    each center moves to the middle of its points

groups = the final assignment

Terms: cluster, centroid

Hierarchical clustering

Hierarchical clustering starts by treating every point as its own tiny group: six points, six groups.

start: every point is its own group
repeat until one group is left:
    find the two closest groups
    merge them
draw the merges as a tree (a dendrogram)
cut the tree at some height → that many groups

Terms: dendrogram

DBSCAN

Draw a small circle around each point and count the neighbors inside it. A point with enough neighbors is a core point: it sits in a crowded area.

radius = 1.0
min_neighbors = 3
for each point:
    if it has ≥ 3 neighbors within the radius → core point
grow clusters by linking core points that reach each other
points no core point can reach → noise

Terms: core point

Principal component analysis

PCA looks for the direction along which the points are most spread out: the first principal component (red). The second one (purple) is at a right angle and captures what’s left.

data = points with many features
find the direction where the data spreads the most   → component 1
find the next one, at a right angle to the first     → component 2
keep the top few directions, drop the rest
each point → its position along the kept directions

Terms: principal component, dimensionality reduction

t-SNE and UMAP

Place the points on a flat map and nudge them over and over: neighbors pull together, strangers push apart. The hidden groups appear as islands.

data = thousands of points with hundreds of features
for each point: note which points are its close neighbors
place every point on a flat map, randomly at first
repeat:
    pull neighbors together, push strangers apart
show the map: similar things end up side by side

Terms:

Anomaly detection

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

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

Terms: anomaly

Revise with flashcards and quizzes. Free practice for every lesson in this chapter.

Open in the app