I was going through the k-means Wikipedia page. Based on the algorithm, I think the complexity is O(n*k*i)
(n
= total elements, k
= number of cluster iteration)
So can someone explain me this statement from Wikipedia and how is this NP hard?
If
k
andd
(the dimension) are fixed, the problem can be exactly solved in timeO(ndk+1 log n)
, wheren
is the number of entities to be clustered.
The space complexity of K-means clustering algorithm is O(N(D + K)). Based on the number of distance calculations, the time complexity of K-means is O(NKI).
Its space complexity is O(k+n).
To achieve this objective, K-means looks for a fixed number (k) of clusters in a dataset.” A cluster refers to a collection of data points aggregated together because of certain similarities. You'll define a target number k, which refers to the number of centroids you need in the dataset.
The cycle can not have length greater than 1 because otherwise by (2) you would have some clustering which has a lower cost than itself which is impossible. Hence the cycle must have length exactly 1. Hence k-means converges in a finite number of iterations.
It depends on what you call k-means.
The problem of finding the global optimum of the k-means objective function
is NP-hard, where Si
is the cluster i
(and there are k
clusters), xj
is the d
-dimensional point in cluster Si
and μi
is the centroid (average of the points) of cluster Si
.
However, running a fixed number t
of iterations of the standard algorithm takes only O(t*k*n*d)
, for n
(d
-dimensional) points, where k
is the number of centroids (or clusters). This what practical implementations do (often with random restarts between the iterations).
The standard algorithm only approximates a local optimum of the above function, and so do all the k-means algorithms that I've seen.
In this answer, note that i
used in the k-means objective formula and i
used in the analysis of the time complexity of k-means (that is, the number of iterations needed until convergence) are different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With