|
150 | 150 | @test report(mach).dendrogram.heights == dendro.heights
|
151 | 151 | end
|
152 | 152 |
|
| 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 | + |
153 | 185 | @testset "MLJ interface" begin
|
154 |
| - models = [KMeans, KMedoids, DBSCAN, HierarchicalClustering] |
| 186 | + models = [KMeans, KMedoids, DBSCAN, HierarchicalClustering, AffinityPropagation] |
155 | 187 | failures, summary = MLJTestInterface.test(
|
156 | 188 | models,
|
157 | 189 | X;
|
|
0 commit comments