Skip to content

Add interface for DBSCAN#17

Merged
ablaom merged 6 commits intomasterfrom
dbscan
Aug 28, 2022
Merged

Add interface for DBSCAN#17
ablaom merged 6 commits intomasterfrom
dbscan

Conversation

@ablaom
Copy link
Member

@ablaom ablaom commented Aug 24, 2022

Replaces #11. Builds on JuliaAI/MLJBase.jl#806, which was not available at that time.

Adds an interface for the DBSCAB model, implementing it as a Static model (no fit), as the model does not generalize to new data. Assignments are returned by predict; DBSCAN point types (core/boundary/noise) are accessed from the post-predict report. Detailed MLJ-compliant doc-string included.

using MLJBase
using MLJClusteringInterface

X, y  = make_moons(400, noise=0.09, rng=1)

model = DBSCAN(radius=0.13, min_cluster_size=5)
mach = machine(model)

# compute and output cluster assignments for observations in `X`:
yhat = predict(mach, X);

# compare with true labels:
compare = zip(yhat, y) |> collect;
julia> compare[1:10] # clusters align with classes
10-element Vector{Tuple{CategoricalArrays.CategoricalValue{Int64, UInt32}, CategoricalArrays.CategoricalValue{Int64, UInt32}}}:
 (1, 1)
 (2, 0)
 (2, 0)
 (1, 1)
 (2, 0)
 (2, 0)
 (2, 0)
 (2, 0)
 (2, 0)
 (2, 0)

# access post-predict report (`C` is core point, `N` is noise):
julia> unique(report(mach).point_types)
2-element Vector{Char}:
 'C': ASCII/Unicode U+0043 (category Lu: Letter, uppercase)
 'N': ASCII/Unicode U+004E (category Lu: Letter, uppercase)

# other report items:
julia> report(mach) |> keys
(:point_types, :nclusters, :cluster_labels, :clusters)

@ablaom
Copy link
Member Author

ablaom commented Aug 24, 2022

@juliohm

@codecov-commenter
Copy link

codecov-commenter commented Aug 24, 2022

Codecov Report

Merging #17 (85cfa5c) into master (867f7f0) will increase coverage by 3.67%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #17      +/-   ##
==========================================
+ Coverage   94.73%   98.41%   +3.67%     
==========================================
  Files           1        1              
  Lines          38       63      +25     
==========================================
+ Hits           36       62      +26     
+ Misses          2        1       -1     
Impacted Files Coverage Δ
src/MLJClusteringInterface.jl 98.41% <100.00%> (+3.67%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@ablaom ablaom requested a review from OkonSamuel August 24, 2022 22:13
Copy link
Member

@OkonSamuel OkonSamuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!!.

@ablaom
Copy link
Member Author

ablaom commented Aug 25, 2022

Thanks @OkonSamuel for your review.

@ablaom ablaom merged commit 39b1fdb into master Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants