Fuzzy C-means
Fuzzy C-means is a clustering method that provides cluster membership weights instead of "hard" classification (e.g. K-means).
From a mathematical standpoint, fuzzy C-means solves the following optimization problem:
\[\arg\min_C \ \sum_{i=1}^n \sum_{j=1}^c w_{ij}^m \| \mathbf{x}_i - \mathbf{c}_{j} \|^2, \
\text{where}\ w_{ij} = \left(\sum_{k=1}^{c} \left(\frac{\left\|\mathbf{x}_i - \mathbf{c}_j \right\|}{\left\|\mathbf{x}_i - \mathbf{c}_k \right\|}\right)^{\frac{2}{m-1}}\right)^{-1}\]
Here, $\mathbf{c}_j$ is the center of the $j$-th cluster, $w_{ij}$ is the membership weight of the $i$-th point in the $j$-th cluster, and $m > 1$ is a user-defined fuzziness parameter.
Clustering.fuzzy_cmeans
— Function.fuzzy_cmeans(data::AbstractMatrix, C::Int, fuzziness::Real,
[...]) -> FuzzyCMeansResult
Perform Fuzzy C-means clustering over the given data
.
Arguments
data::AbstractMatrix
: $d×n$ data matrix. Each column represents one $d$-dimensional data point.C::Int
: the number of fuzzy clusters, $2 ≤ C < n$.fuzziness::Real
: clusters fuzziness (see $m$ in the mathematical formulation), $\mathrm{fuzziness} > 1$.
Optional keyword arguments:
dist_metric::Metric
(defaults toEuclidean
): theMetric
object that defines the distance between the data pointsmaxiter
,tol
,display
: see common options
Clustering.FuzzyCMeansResult
— Type.FuzzyCMeansResult{T<:AbstractFloat}
The output of fuzzy_cmeans
function.
Fields
centers::Matrix{T}
: the $d×C$ matrix with columns being the centers of resulting fuzzy clustersweights::Matrix{Float64}
: the $n×C$ matrix of assignment weights ($\mathrm{weights}_{ij}$ is the weight (probability) of assigning $i$-th point to the $j$-th cluster)iterations::Int
: the number of executed algorithm iterationsconverged::Bool
: whether the procedure converged
Missing docstring.
Missing docstring for wcounts(::FuzzyCMeansResult)
. Check Documenter's build log for details.
Examples
using Clustering
# make a random dataset with 1000 points
# each point is a 5-dimensional vector
X = rand(5, 1000)
# performs Fuzzy C-means over X, trying to group them into 3 clusters
# with a fuzziness factor of 2. Set maximum number of iterations to 200
# set display to :iter, so it shows progressive info at each iteration
R = fuzzy_cmeans(X, 3, 2, maxiter=200, display=:iter)
# get the centers (i.e. weighted mean vectors)
# M is a 5x3 matrix
# M[:, k] is the center of the k-th cluster
M = R.centers
# get the point memberships over all the clusters
# memberships is a 20x3 matrix
memberships = R.weights
1000×3 Array{Float64,2}:
0.332426 0.335326 0.332249
0.338547 0.330885 0.330569
0.336168 0.332667 0.331166
0.335341 0.333433 0.331227
0.334174 0.332594 0.333232
0.331969 0.33368 0.334351
0.33327 0.333149 0.333581
0.333658 0.335752 0.33059
0.332174 0.335772 0.332054
0.334529 0.334403 0.331068
⋮
0.336722 0.330313 0.332965
0.33687 0.332734 0.330396
0.329968 0.333983 0.336049
0.331693 0.333535 0.334772
0.335914 0.333517 0.330568
0.330851 0.335326 0.333822
0.334354 0.333439 0.332206
0.33422 0.333913 0.331868
0.332509 0.334279 0.333212