Skip to content

Commit fb174d9

Browse files
authored
Merge pull request #25 from JuliaAI/clustering-0-15-compat
Bump compat for Clustering to 0.15
2 parents 7bae312 + 35e8d7e commit fb174d9

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
name = "MLJClusteringInterface"
22
uuid = "d354fa79-ed1c-40d4-88ef-b8c7bd1568af"
33
authors = ["Anthony D. Blaom <[email protected]>", "Thibaut Lienart <[email protected]>", "Okon Samuel <[email protected]>"]
4-
version = "0.1.9"
4+
version = "0.1.10"
55

66
[deps]
77
Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
88
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
99
MLJModelInterface = "e80e1ace-859a-464e-9ed9-23947d8ae3ea"
1010

1111
[compat]
12-
Clustering = "0.14"
12+
Clustering = "0.15"
1313
Distances = "0.9, 0.10"
1414
MLJModelInterface = "1.4"
1515
julia = "1.6"

src/MLJClusteringInterface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function MMI.predict(model::DBSCAN, ::Nothing, X)
139139
leafsize=model.leafsize,
140140
min_neighbors=model.min_neighbors,
141141
min_cluster_size=model.min_cluster_size,
142-
)
142+
).clusters
143143
nclusters = length(clusters)
144144

145145
# assignments and point types

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
55
MLJBase = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
66
MLJTestInterface = "72560011-54dd-4dc2-94f3-c5de45b75ecd"
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
8+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
89
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import LinearAlgebra: norm
55
using MLJBase
66
using MLJTestInterface
77
using MLJClusteringInterface
8-
using Random: seed!
8+
using StableRNGs
9+
using Random
910
using Test
1011

11-
seed!(132442)
12+
srng(n) = StableRNGs.StableRNG(n)
1213
X, y = @load_crabs
1314

1415

@@ -59,6 +60,35 @@ end
5960

6061
@testset "DBSCAN" begin
6162

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+
6292
# five spot pattern
6393
X = [
6494
0.0 0.0
@@ -72,7 +102,7 @@ end
72102
dbscan = DBSCAN(radius=0.1)
73103
yhat1, report1 = predict(dbscan, nothing, X)
74104
@test report1.nclusters == 5
75-
@test report1.point_types == fill('B', 5)
105+
@test report1.point_types == fill('C', 5)
76106
@test Set(yhat1) == Set(unique(yhat1))
77107
@test Set(report1.cluster_labels) == Set(unique(yhat1))
78108

0 commit comments

Comments
 (0)