Written and maintained by CASRAI Editorial Board
Published
On this page
Cmeans commonly refers to fuzzy c-means clustering, an algorithm that gives each observation a degree of membership in every cluster. Unlike a single hard label, these memberships preserve overlap. The example below shows exactly how distances become memberships and how those memberships move the cluster centers.
Definition of cmeans and fuzzy clustering
Fuzzy c-means, abbreviated FCM, partitions numerical observations around a chosen number of centers while allowing partial membership in multiple clusters. For each observation, the memberships are nonnegative and sum to one. Fitting alternates between calculating centers from weighted observations and recalculating memberships from distances. The fuzzifier, usually written m, controls the membership weighting and must exceed one. The R e1071 manual describes cmeans as a fuzzy version of k-means; its output contains both the membership matrix and a closest hard clustering.
The distinction matters when an analyst wants to describe observations that sit between groups. A hard assignment records only the winning cluster; a fuzzy result retains the whole membership profile. For the hard-assignment counterpart, see the k-means formula and worked example.
The name needs context: this guide covers fuzzy c-means, including e1071’s cmeans function. Software using the same name for a capacitated or constrained k-means algorithm addresses a different problem. Bezdek’s Pattern Recognition with Fuzzy Objective Function Algorithms provides the historical textbook context for graded belonging and fuzzy objective functions; its publisher identifies fuzzy ISODATA with fuzzy c-means.
Fuzzy c means clustering formula
For ordinary, unweighted, squared-Euclidean FCM, minimize the objective J over memberships U and centers V:
J = Σᵢ₌₁ᴺ Σⱼ₌₁ᶜ uᵢⱼᵐ ‖xᵢ − vⱼ‖²
N is the number of observations; c is the specified number of clusters; i indexes observations and j indexes clusters. The vector xᵢ contains observation i’s numerical features, vⱼ is center j, and ‖xᵢ − vⱼ‖ is their Euclidean distance. The scalar uᵢⱼ is the membership of observation i in cluster j. The exponent m is the fuzzifier. U collects all memberships, V all centers, and Σ means summation. Memberships satisfy Σⱼ uᵢⱼ = 1 for each i.
For positive distances dᵢⱼ = ‖xᵢ − vⱼ‖, the alternating updates can be written:
vⱼ = [Σᵢ uᵢⱼᵐ xᵢ] / [Σᵢ uᵢⱼᵐ]
uᵢⱼ = dᵢⱼ^(−2/(m−1)) / [Σₖ₌₁ᶜ dᵢₖ^(−2/(m−1))]
Here k is another cluster index used in the denominator. The center is a membership-powered weighted mean. The membership update normalizes inverse-distance weights across the centers for one observation. With m = 2, the weights are inverse squared distances. These expressions follow the scikit-fuzzy implementation, whose objective explicitly squares Euclidean distances.
A zero distance needs special handling because a negative power of zero is undefined. An observation coinciding with one distinct center can receive full membership there; coincident centers require a tie convention. Implementations also use numerical safeguards. The examples here deliberately use nonzero distances so the arithmetic remains transparent.
Worked c means clustering example
This is an illustrative numerical example, not an empirical research dataset. Take three one-dimensional observations x = [0, 4, 10], two initial centers v₁ = 1 and v₂ = 9, and m = 2. We will calculate one membership update followed by one center update. These are intermediate calculations, not a claim that the algorithm has converged.
For x = 4, the distances are |4 − 1| = 3 and |4 − 9| = 5. Their squared values are 9 and 25. Therefore:
u₄,₁ = (1/9) / [(1/9) + (1/25)] = 25/34 ≈ 0.735294
u₄,₂ = 9/34 ≈ 0.264706
The same calculation gives memberships (81/82, 1/82) for x = 0 and (1/82, 81/82) for x = 10. Each pair sums to one. Although 4 is closer to center 1, it still contributes to center 2 because its second membership is positive.
To update the first center, square its memberships and form the weighted mean:
v₁,new = [0 × (81/82)² + 4 × (25/34)² + 10 × (1/82)²] / [(81/82)² + (25/34)² + (1/82)²] ≈ 1.426986
For the second center, substitute the other membership column:
v₂,new = [0 × (1/82)² + 4 × (9/34)² + 10 × (81/82)²] / [(1/82)² + (9/34)² + (81/82)²] ≈ 9.596642
Both updates use all three observations. The first center moves right because the observation at 4 carries appreciable weight; the second moves toward 10 because that observation has much greater membership there than 4 does. Recalculate memberships using the new centers before proceeding to another center update.
As a separate check, evaluate J using the initial centers and the memberships calculated from them. The contributions of observations 0 and 10 are each 81/82; the contribution of 4 is 225/34. Thus J = 81/82 + 225/34 + 81/82 ≈ 8.593257. Mixing new centers with an old reported objective would describe a different stage of the calculation.
Interpreting FCM clustering
Membership measures relative compatibility with the fitted centers under the chosen distance and fuzzifier. It is not automatically a calibrated probability that an observation belongs to a real population. In this example, 0.735294 means that the first center receives the larger normalized inverse-distance weight for observation 4.
| Example result | Reading guidance |
|---|---|
| Memberships 25/34 and 9/34 | The first center is favored, but the second membership remains visible. |
| Memberships 1/2 and 1/2 | Equal distances give equal compatibility; this alone says nothing about absolute distance. |
| Hard label: first cluster | The larger membership wins; the discarded second value still describes overlap. |
The first row is calculated above; the second follows directly by substituting equal distances into the update; the third applies the maximum-membership rule documented in e1071 and the scikit-fuzzy example. There is no universal membership threshold implied by these rows.
Consider fixed two-dimensional centers (−1, 0) and (1, 0). The points (0, 0) and (0, 100) are each equally distant from those two centers, so both receive memberships (0.5, 0.5). Yet the first point is distance 1 from each center and the second is distance √10001. Equal memberships can therefore describe a nearby boundary point or a very remote point. Inspect distances alongside memberships.
The fuzzy partition coefficient summarizes membership concentration: FPC = (1/N) ΣᵢΣⱼ uᵢⱼ². For the three-observation example, FPC ≈ 0.854180. With c equally weighted memberships per observation, substitution gives FPC = 1/c; completely hard memberships give 1. These are algebraic reference points, not acceptance cutoffs. The official scikit-fuzzy example notes that c = 1 trivially gives FPC = 1, so that value cannot by itself establish a useful grouping.
Assumptions and common mistakes
FCM requires an explicit distance geometry and a selected cluster count. Neither is discovered merely by calling a function. For a squared-Euclidean analysis, changing a feature’s unit changes its squared contribution to distance. Multiplying one feature by 100 multiplies that feature’s squared-distance contribution by 10,000. Decide whether that weighting is scientifically meaningful before interpreting the groups.
Confusing distances with squared distances changes the algorithm. For distances 3 and 5 at m = 2, inverse-distance normalization would give 5/8 = 0.625, whereas inverse-squared-distance normalization gives 25/34 ≈ 0.735294. If your worksheet produces the first number for this example, check the exponent.
Changing m legitimately changes those weights. Setting m to 3 makes the exponent −1, giving membership 0.625 for the nearer center. Thus two analyses using different fuzzifiers can disagree despite identical observations, centers and distances.
Initialization and stopping settings also matter. The e1071 manual allows initial centers to be supplied directly or selected randomly from observations. Scikit-fuzzy can initialize memberships randomly and exposes a membership-change tolerance. Preserve the initialization and stopping rule with the analysis. A completed iteration limit does not, by itself, demonstrate that the requested tolerance was met.
Scikit-fuzzy documents a high-dimensional failure mode in which centers can be pulled toward the overall center of gravity. Examine center locations rather than assuming that more measured features produce more distinct groups. Its example also warns that center order can change between runs: compare coordinates before treating cluster numbers as stable names.
Finally, retaining only the winning label erases the feature that distinguishes fuzzy clustering. Keep memberships available when reporting borderline observations. For broader workflows, see cluster analysis in R and cluster analysis in Python; the fuzzy calculations here complement those general introductions.
How to report fuzzy c-means clustering
An APA-style methods/results paragraph should identify the observations and features, preprocessing, distance, c, m, initialization, stopping criterion, software, and the outputs being interpreted. Include the membership matrix or an appropriate summary, rather than describing hard labels as the entire fuzzy result. This is an illustrative reporting model, not an APA-mandated statistical template:
We illustrated squared-Euclidean fuzzy c-means calculations for three observations (0, 4, and 10), with two initial centers (1 and 9) and a fuzzifier of 2. One membership update assigned the observation at 4 memberships of .735 and .265. The subsequent center update produced centers of 1.427 and 9.597. These intermediate values illustrate the update equations and do not represent a converged fit.
For an actual study, replace the illustrative settings with the recorded analysis settings and report the stopping outcome. A single update, an objective value, and a final fitted partition are different results. Name which one a table contains so another analyst can reproduce the calculation being discussed.
How to calculate c-means clustering in Excel, R and Python
The following short snippets reproduce the membership update for observation 4 with centers 1 and 9 and m = 2. They hold the centers fixed. A complete fit alternates these memberships with center updates until its stopping rule is satisfied.
Excel membership formula
Put 4 in A2, 1 in B1, and 9 in C1. For the first membership enter:
=1/(1+((A2-$B$1)/(A2-$C$1))^2)
This yields 25/34. The second membership is one minus that result. This compact formula assumes both distances are nonzero; handle observations coinciding with a center separately. It is an arithmetic illustration, not a built-in Excel FCM command.
R membership calculation and cmeans
x = 4
centers = c(1, 9)
w = 1 / (x - centers)^2
u = w / sum(w)
u
The two values are approximately 0.735294 and 0.264706. For fitting a data matrix, e1071 provides cmeans; its rows represent observations. Supply centers and m explicitly when documenting a reproducible analysis.
Python membership calculation
x = 4
centers = [1, 9]
w = [1 / (x - center)**2 for center in centers]
u = [weight / sum(w) for weight in w]
print(u)
This produces the same pair. Scikit-fuzzy’s full cmeans function expects features in rows and observations in columns, so a conventional observations-by-features matrix needs transposing. The downloadable data table below compares the R and Python interfaces, including initialization and stopping controls. It keeps implementation differences separate from the mathematical update illustrated here.
Sources
- e1071 authors: package reference manual, cmeans, checked 2026-11-17.
- Scikit-fuzzy: Module: cluster API reference, checked 2026-11-17.
- Scikit-fuzzy: source code for skfuzzy.cluster._cmeans, checked 2026-11-17.
- Scikit-fuzzy: Fuzzy c-means clustering example, checked 2026-11-17.
- Springer: Bezdek, Pattern Recognition with Fuzzy Objective Function Algorithms, publisher overview, checked 2026-11-17.
Data: Fuzzy c-means interfaces in R and Python
Original crosswalk compiled from the e1071 cmeans reference and the scikit-fuzzy cluster API and implementation. It compares the corresponding input conventions, parameter names and initialization and stopping controls; it does not imply identical numerical trajectories.
| Analysis element | R e1071 cmeans | Python skfuzzy.cluster.cmeans |
|---|---|---|
| Input orientation | Observations in rows; variables in columns | Features in rows; observations in columns |
| Cluster count | centers: integer number of clusters | c: integer number of clusters |
| Fuzzifier | m: degree of fuzzification, greater than 1 | m: membership exponent in the update |
| Initialization | centers matrix supplies initial centers; integer selects random data rows | init supplies memberships; seed controls random initialization if init is absent |
| Iteration limit | iter.max | maxiter |
| Convergence control | control list: reltol for objective reduction | error: norm of successive membership-matrix differences |
Sources
- e1071 reference manual: cmeans (accessed 2026-11-17)
- Scikit-fuzzy cluster API (accessed 2026-11-17)
- Scikit-fuzzy cmeans implementation (accessed 2026-11-17)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







