programlibs/Learn/demos/blobs.xtl

Learn's four models on one set of points: three blobs of 20 (around 0 0, 6 6 and 0 6, a fixed ripple instead of chance). k-means finds them without their labels; kNN and logistic regression learn them from their labels; PCA finds the direction they spread along most. Run with "just demo-lib Learn blobs".

source · imports ml: libs/Learn/src/Learn.xtl

i : Int

value · line 10
i ← o̲ffsets 60
Used in: blob, X

blob : Int

value · line 11
blob ← 1 + i d̲iv 20

cx : Float

value · line 12
cx ← (1 + blob = 2) s̲elect 0.0 6.0
Used in: X

cy : Float

value · line 13
cy ← (1 + blob = 1) s̲elect 6.0 0.0
Used in: X

X : Float

value · line 14
X ← o̲\ 2 60 r̲eshape (cx + 0.8 × s̲in 1.3 × f̲loat i) c̲at cy + 0.8 × c̲os 2.1 × f̲loat i

C : Float

value · line 16

k-means: the three centers found, and which cluster each point is in.

C ← (3, 10) ᵐˡk̲means X

ᵘr̲ound : Float -> Float

function · line 17
ᵘr̲ound ← { a → (f̲loat f̲loor 0.5 + 100.0 × a) ÷ 100.0 }

Q : Float

value · line 21

kNN (5 neighbors) and logistic regression on four new points.

Q ← 4 2 r̲eshape 1.0 1.0 5.0 5.0 0.5 5.0 3.0 3.0

W : Float

value · line 23
W ← (200, 0.5) ᵐˡl̲ogistic (X, blob)

mu : Float

value · line 26

PCA: the direction of most spread, and the share of the variance on it.

(mu, V, ev) ← 2 ᵐˡp̲ca X
Used in: mu

V : Float

value · line 26

PCA: the direction of most spread, and the share of the variance on it.

(mu, V, ev) ← 2 ᵐˡp̲ca X

ev : Float

value · line 26

PCA: the direction of most spread, and the share of the variance on it.

(mu, V, ev) ← 2 ᵐˡp̲ca X