3
$\begingroup$

If I had a vector of weights for each observation

data(iris)
wghts <- abs(rnorm(nrow(iris)))

And I had a function that did not accept weights as an argument:

kmeans(iris[-5], centers=3)

Can I multiply each variable by the weights to get the desired output?

There is a version of kmeans that accepts weights:

library(FactoClass)
kmeansW(iris[-5], centers=3, weight=wghts)

But there are aspects of regular kmeans output that I still want, including betweenss. And just for learning purposes, Is it possible to just multiply all observations by the weight vector to get the equivalent output?

newdf <- iris[-5]
newdf[] <- lapply(newdf, function(v) v*wghts)
kmeans(newdf, centers=3)

Did I successfully "add" the weights by multiplying each variable by the weights or am I missing some aspect of weighted kmeans theory?

In other words, is

kmeans(newdf, centers=3) structurally equivalent to kmeansW(iris[-5], centers=3, weight=wghts)?

$\endgroup$
1
  • 2
    $\begingroup$ Imagine--geometrically--what would happen if, say, you multiplied half of the data randomly by $0.001$. Obviously, those data would all cluster near zero. If your clustering procedure is any good at all, it will pick that up and put those data into the same cluster. How meaningful would that be? $\endgroup$
    – whuber
    Jun 6 '16 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.