这是我的代码,绘图函数绘制的区域可以获得,但不适用于数据。除了plot.ksvm绘制的数据外,轴是正常的:x和y轴是反转的。为什么?以及如何修复它?
library(kernlab)
set.seed(77)
# sets constructions
## 1st set: uniform in a rectangle
x1.n = 200 # number of sample
x1.ymin = -10
x1.ymax = 8
x1.xmin = 0
x1.xmax = 18
x1 <- cbind(runif(x1.n, x1.xmin, x1.xmax), runif(x1.n, x1.ymin, x1.ymax))
## 2nd set: uniform into a ball
x2.n = 20 # number of sample
x2.c = c(-1,3) # center
x2.r = 2 # radius
angles = runif(x2.n, -pi, pi)
r = runif(x2.n, 0, x2.r)
x2 <- cbind(cos(angles) * r, sin(angles) * r)
#plot(x2)
training.set=rbind(x1, x2)
training.label=c(rep.int(-1, times=x1.n), rep.int(1, times=x2.n))
rbf <- rbfdot(sigma=.1)
K.gaussian=kernelMatrix(rbf, training.set)
K.linear=kernelMatrix(vanilladot(), training.set)
# plot and svm
plot(training.set, col=training.label+3)
s <- ksvm(training.set, training.label,type="C-svc")
X11()
plot(s, data=training.set)
X11()
plot(s, data=cbind(training.set[,2], training.set[,1]))