Fuzzy C-means

# 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.

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 to Euclidean): the Metric object that defines the distance between the data points
• maxiter, tol, display: see common options
source
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 clusters
• weights::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 iterations
• converged::Bool: whether the procedure converged
source
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.33524   0.333421  0.331338
0.333106  0.33282   0.334075
0.333824  0.3336    0.332576
0.333118  0.334131  0.332751
0.334754  0.333221  0.332025
0.334431  0.331654  0.333915
0.333676  0.335062  0.331262
0.333568  0.332304  0.334128
0.335612  0.332474  0.331914
0.337521  0.331283  0.331197
⋮
0.332836  0.33152   0.335644
0.332368  0.333253  0.334379
0.333232  0.333394  0.333374
0.332229  0.33312   0.334651
0.335162  0.332332  0.332506
0.33566   0.331392  0.332948
0.331479  0.333362  0.335159
0.33249   0.333248  0.334262
0.332082  0.334983  0.332936