Skip to content

Instantly share code, notes, and snippets.

@davidechicco
Last active July 22, 2026 11:24
Show Gist options
  • Select an option

  • Save davidechicco/467a88138a7f4816639faf64292e8045 to your computer and use it in GitHub Desktop.

Select an option

Save davidechicco/467a88138a7f4816639faf64292e8045 to your computer and use it in GitHub Desktop.
hdbscan_example_single_shot.jl
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