KMedoidsClusterer
mutable struct KMedoidsClusterer <: MLJModelInterface.Unsupervised
Parameters:
n_classes::Int64
: Number of classes to discriminate the data [def: 3]dist::Function
: Function to employ as distance. Default to the Euclidean distance. Can be one of the predefined distances (l1_distance
,l2_distance
,l2squared_distance
),cosine_distance
), any user defined function accepting two vectors and returning a scalar or an anonymous function with the same characteristics.initialisation_strategy::String
: The computation method of the vector of the initial representatives. One of the following:- "random": randomly in the X space
- "grid": using a grid approach
- "shuffle": selecting randomly within the available points [default]
- "given": using a provided set of initial representatives provided in the
initial_representatives
parameter
initial_representatives::Union{Nothing, Matrix{Float64}}
: Provided (K x D) matrix of initial representatives (useful only withinitialisation_strategy="given"
) [default:nothing
]rng::Random.AbstractRNG
: Random Number Generator [deafult:Random.GLOBAL_RNG
]
The K-medoids clustering algorithm with customisable distance function, from the Beta Machine Learning Toolkit (BetaML).
Similar to K-Means, but the "representatives" (the cetroids) are guaranteed to be one of the training points. The algorithm work with any arbitrary distance measure.
Notes:
- data must be numerical
- online fitting (re-fitting with new data) is supported
Example:
julia> using MLJ
julia> X, y = @load_iris;
julia> modelType = @load KMedoidsClusterer pkg = "BetaML" verbosity=0
BetaML.Clustering.KMedoidsClusterer
julia> model = modelType()
KMedoidsClusterer(
n_classes = 3,
dist = BetaML.Clustering.var"#39#41"(),
initialisation_strategy = "shuffle",
initial_representatives = nothing,
rng = Random._GLOBAL_RNG())
julia> mach = machine(model, X);
julia> fit!(mach);
[ Info: Training machine(KMedoidsClusterer(n_classes = 3, …), …).
julia> classes_est = predict(mach, X);
julia> hcat(y,classes_est)
150×2 CategoricalArrays.CategoricalArray{Union{Int64, String},2,UInt32}:
"setosa" 3
"setosa" 3
"setosa" 3
⋮
"virginica" 1
"virginica" 1
"virginica" 2