## a binary classification problem
x = matrix(c(rnorm(80, mean = -1), rnorm(80, mean = 1)),
ncol = 2, byrow = TRUE)
y = matrix(rnorm(20, mean = 0, sd = 1.2), ncol = 2)
knn.ani(train = x, test = y, cl = rep(c("first class", "second class"),
each = 40), k = 30, control = ani.control(interval = 2))
ani.start()
op = par(mar = c(3.5, 3.5, 3, 1), mgp = c(2, 0.5,
0), cex.axis = 0.75, tcl = -0.3)
knn.ani(train = x, test = y, cl = rep(c("first class", "second class"),
each = 40), k = 30, control = ani.control(saveANI = TRUE,
width = 600, height = 600))
par(op)
ani.stop()
## this is an interactive demo; just click your mouse
knn.ani(train = x, cl = rep(c("first class", "second class"),
each = 40), k = 30, nmax = 5, interact = TRUE)
Run the code above in your browser using DataLab