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.332687 0.332566 0.334747
0.333311 0.333275 0.333414
0.333581 0.333197 0.333223
0.331212 0.334853 0.333935
0.332916 0.33288 0.334204
0.334561 0.332931 0.332508
0.33173 0.336071 0.332199
0.335626 0.332506 0.331868
0.331009 0.334966 0.334025
0.332777 0.334055 0.333169
⋮
0.334764 0.33347 0.331766
0.331685 0.334359 0.333956
0.331176 0.333994 0.33483
0.333982 0.333628 0.33239
0.333607 0.331976 0.334417
0.33087 0.335357 0.333774
0.33393 0.333991 0.332079
0.333438 0.333452 0.33311
0.333656 0.333123 0.333221