Last active
July 22, 2026 11:24
-
-
Save davidechicco/467a88138a7f4816639faf64292e8045 to your computer and use it in GitHub Desktop.
hdbscan_example_single_shot.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Pkg | |
| # ---------------------------------------------------------- | |
| # Install missing packages | |
| # ---------------------------------------------------------- | |
| function ensure_package(pkg::String) | |
| try | |
| Base.eval(Main, Meta.parse("using $pkg")) | |
| println("$pkg already available") | |
| catch | |
| println("Installing $pkg ...") | |
| Pkg.add(pkg) | |
| end | |
| end | |
| for pkg in [ | |
| "MLJ", | |
| "HDBSCAN", | |
| "DensityBasedClusteringValidation", | |
| "Printf" | |
| ] | |
| ensure_package(pkg) | |
| end | |
| import Pkg | |
| Pkg.add("MLJ") | |
| import HDBSCAN | |
| import MLJ | |
| using Printf | |
| X, y = MLJ.make_blobs(1000, 2, as_table=false) | |
| this_min_cluster_size = 2 | |
| this_min_sample_size = 5 | |
| model = HDBSCAN.Hdbscan(this_min_cluster_size, this_min_sample_size; metric="euclidean", | |
| copy = true) | |
| HDBSCAN.fit!(model, X) | |
| labels = HDBSCAN.labels(model) | |
| probabilities = HDBSCAN.probabilities(model) | |
| dbcv_score = dbcv( | |
| X, | |
| labels | |
| ) | |
| println( | |
| "DBCV score = ", | |
| @sprintf("%.10f", dbcv_score) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment