Error in colMeans(x, na.rm = TRUE) : ‘x’ must be numeric in KNN classification

‘Color’ is a factor. kNN only takes numeric inputs. You can turn your Color variable into a numeric variable or just remove Color entirely.

dat$color = as.numeric(dat$color)

Leave a Comment