I am trying to implement kmeans clustering algorithm using Manhattan distance. I used the following code for implementing the same:
data<- read.csv("garments_worker_productivity.csv")
cluster<-kmeans(data,3,iter.max=10, nstart=1, method = "Manhattan")
I am receiving the following error:
Error in kmeans(data, 3, iter.max = 10, nstart = 1, method = "manhattan") :
unused argument (method = "Manhattan")
so how do I implement kmeans using Manhattan and Minkowski distance in r without an error?
thank you!
FJCC
August 4, 2021, 9:13pm
2
The kmeans function in the stats package has an argument named algorithm . None of the values it can have is "manhattan".
kmeans(x, centers, iter.max = 10, nstart = 1,
algorithm = c("Hartigan-Wong", "Lloyd", "Forgy",
"MacQueen"), trace=FALSE)
Is that the function you are using?
yes. I realised I was trying this function in amap package
Kmeans(x, centers, iter.max = 10, nstart = 1,
method = "euclidean")
Is there any other way where I can use Manhattan or Minkowski distance instead of the traditional Euclidean distance in the Kmeans algorithm? Please do let me know how.
Thank you!
FJCC
August 5, 2021, 3:53am
4
Kmeans() accepts the following values of method :
"euclidean", "maximum",
"manhattan", "canberra", "binary", "pearson" , "abspearson" , "abscorrelation",
"correlation", "spearman" or "kendall"
Notice "manhattan" is all lower case.
Still it shows the same error
FJCC
August 5, 2021, 4:08am
6
kmeans is the function from the stats package. Kmeans, with an uppercase K, is the function from amap. Case matters in R.
it says that the function isn't found ;(
FJCC
August 5, 2021, 5:03am
8
Did you run
library(amap)
before trying to use Kmeans()? That assumes you have installed the amap package.
yes I did. amap package is installed
I removed the line
library(amap)
and it worked.. I still don't know why.. thanks though!
system
Closed
August 26, 2021, 5:19am
11
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.