@@ -5,10 +5,11 @@ import LinearAlgebra: norm
5
5
using MLJBase
6
6
using MLJTestInterface
7
7
using MLJClusteringInterface
8
- using Random: seed!
8
+ using StableRNGs
9
+ using Random
9
10
using Test
10
11
11
- seed! ( 132442 )
12
+ srng (n) = StableRNGs . StableRNG (n )
12
13
X, y = @load_crabs
13
14
14
15
59
60
60
61
@testset " DBSCAN" begin
61
62
63
+ # test interface is faithful on some synthetic data:
64
+ X, _ = make_moons (500 , rng= srng (123 ))
65
+ dbscan = DBSCAN (radius= 0.15 , min_neighbors= 3 )
66
+ yhat3, _report = predict (dbscan, nothing , X)
67
+ Xarray = MLJBase. matrix (X)'
68
+ clusters = Clustering. dbscan (
69
+ Xarray,
70
+ dbscan. radius;
71
+ leafsize= dbscan. leafsize,
72
+ min_neighbors= dbscan. min_neighbors,
73
+ min_cluster_size= dbscan. min_cluster_size,
74
+ ). clusters
75
+ noisy_indices = Set (1 : length (y)) # initialization
76
+ for (k, cluster) in enumerate (clusters)
77
+ for i in cluster. core_indices
78
+ delete! (noisy_indices, i)
79
+ @test _report. point_types[i] == ' C'
80
+ @test yhat3[i] == k
81
+ end
82
+ for i in cluster. boundary_indices
83
+ delete! (noisy_indices, i)
84
+ @test _report. point_types[i] == ' B'
85
+ @test yhat3[i] == k
86
+ end
87
+ end
88
+ @test all (noisy_indices) do i
89
+ _report. point_types[i] == ' N' && yhat3[i] == 0
90
+ end
91
+
62
92
# five spot pattern
63
93
X = [
64
94
0.0 0.0
72
102
dbscan = DBSCAN (radius= 0.1 )
73
103
yhat1, report1 = predict (dbscan, nothing , X)
74
104
@test report1. nclusters == 5
75
- @test report1. point_types == fill (' B ' , 5 )
105
+ @test report1. point_types == fill (' C ' , 5 )
76
106
@test Set (yhat1) == Set (unique (yhat1))
77
107
@test Set (report1. cluster_labels) == Set (unique (yhat1))
78
108
0 commit comments