Skip to content

Commit da6e69c

Browse files
committed
Add test for Affinity Propagation
1 parent fc87b92 commit da6e69c

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

test/runtests.jl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,40 @@ end
150150
@test report(mach).dendrogram.heights == dendro.heights
151151
end
152152

153+
# # AffinityPropagation
154+
155+
@testset "AffinityPropagation" begin
156+
X = table(stack(Iterators.partition(0.5:0.5:20, 5))')
157+
158+
# Test case 1: preference == median (negative) similarity (i.e. unspecified)
159+
mach = machine(AffinityPropagation())
160+
161+
yhat = predict(mach, X)
162+
@test yhat == [1, 1, 1, 1, 2, 2, 2, 2]
163+
164+
_report = report(mach)
165+
@test _report.exemplars == [2, 7]
166+
@test _report.centers == [3.0 15.5; 3.5 16.0; 4.0 16.5; 4.5 17.0; 5.0 17.5]
167+
@test _report.cluster_labels == [1, 2]
168+
@test _report.iterations == 50
169+
@test _report.converged == true
170+
171+
# Test case 2: |preference| too large
172+
mach2 = machine(AffinityPropagation(preference=-20.0))
173+
174+
yhat = predict(mach2, X)
175+
@test yhat == [1, 2, 3, 4, 5, 6, 7, 8]
176+
177+
_report = report(mach2)
178+
@test _report.exemplars == [1, 2, 3, 4, 5, 6, 7, 8]
179+
@test _report.centers == matrix(X)'
180+
@test _report.cluster_labels == [1, 2, 3, 4, 5, 6, 7, 8]
181+
@test _report.iterations == 32
182+
@test _report.converged == true
183+
end
184+
153185
@testset "MLJ interface" begin
154-
models = [KMeans, KMedoids, DBSCAN, HierarchicalClustering]
186+
models = [KMeans, KMedoids, DBSCAN, HierarchicalClustering, AffinityPropagation]
155187
failures, summary = MLJTestInterface.test(
156188
models,
157189
X;

0 commit comments

Comments
 (0)