Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y' while trying to implement K-means algorithm in R

r
machine_learning
k-meansclustering
data_science

#1

Hello,

I was trying to implement K-means algorithm with a dataset.

sub=sample_n(train,100)
kmeansdata=data.frame(sub$temp,sub$humidity)
kmeans=kmeans(kmeansdata,centers=3)
kmeans$centers
sub.temp sub.humidity
1 23.37000 35.07692
2 20.28839 56.80645
3 19.16512 81.53488
plot(kmeans)

and I am getting an error saying

Error in xy.coords(x, y, xlabel, ylabel, log) :
‘x’ is a list, but does not have components ‘x’ and ‘y’

Why is this error coming and how to remove it?

Thanks.


#2

you need to specify x, y data for plot command . if you see you have just specified kmeans and it will have a list of data you need to be more clear

instead try and do kmeans with the rattle GUI package