Skip to content

Commit a8c32c3

Browse files
committed
Add more tests for KMedoids
1 parent 9d5f3ff commit a8c32c3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

test/transforms/kmedoids.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
@testset "KMedoids" begin
22
@test !isrevertible(KMedoids(3))
3-
@test TT.parameters(KMedoids(3)) == (k=3,)
43

4+
@test TT.parameters(KMedoids(3)) == (; k=3)
5+
6+
# basic test with continuous variables
57
a = [randn(100); 10 .+ randn(100)]
68
b = [randn(100); 10 .+ randn(100)]
79
t = Table(; a, b)
8-
9-
c = t |> KMedoids(2; rng)
10-
i1 = findall(isequal(1), c.cluster)
11-
i2 = findall(isequal(2), c.cluster)
10+
n = t |> KMedoids(2; rng)
11+
i1 = findall(isequal(1), n.cluster)
12+
i2 = findall(isequal(2), n.cluster)
1213
@test mean(t.a[i1]) > 5
1314
@test mean(t.b[i1]) > 5
1415
@test mean(t.a[i2]) < 5
1516
@test mean(t.b[i2]) < 5
17+
18+
# test with mixed variables
19+
a = [1, 2, 3]
20+
b = [1.0, 2.0, 3.0]
21+
c = ["a", "b", "c"]
22+
t = Table(; a, b, c)
23+
n = t |> KMedoids(3; rng)
24+
@test sort(n.cluster) == [1, 2, 3]
1625
end

0 commit comments

Comments
 (0)