我有这个
library(MASS)
mydata.qda <- qda(Sp ~ ., prior = c(1,1,1)/3, data = mydata.learn)
我想把我的结果画得像 http://scikit-learn.org/0.10/auto_examples/plot_lda_vs_qda.html
答案 0 :(得分:0)
你应该解释你想要绘制的内容,这里有一些例子
https://tgmstat.wordpress.com/2014/01/15/computing-and-visualizing-lda-in-r/ http://www.statmethods.net/advstats/discriminant.html
如果您发布示例数据并说出您想要绘制的内容,您可以获得更多帮助
答案 1 :(得分:0)
您可以使用contour
绘制区分群集的线。这是一个例子。我按照http://www.cbcb.umd.edu/~hcorrada/PracticalML/src/prostate.R
set.seed(357)
Ng <- 100
group.a.x <- seq(from = -3, to = 4, length.out = Ng)
group.a.y <- 6 + 0.3 * group.a.x - 0.3 * group.a.x^2 + rnorm(Ng, sd = 1)
group.a <- data.frame(x = group.a.x, y = group.a.y, group = "A")
group.b.x <- rnorm(n = Ng, mean = 0.5, sd = 0.8)
group.b.y <- rnorm(n = Ng, mean = 2, sd = 0.8)
group.b <- data.frame(x = group.b.x, y = group.b.y, group = "B")
my.xyc <- rbind(group.a, group.b)
plot(my.xyc[, 1:2], col = my.xyc$group)
library(MASS)
mdl <- qda(group ~ x + y, data = my.xyc)
np <- 300
nd.x <- seq(from = min(my.xyc$x), to = max(my.xyc$x), length.out = np)
nd.y <- seq(from = min(my.xyc$y), to = max(my.xyc$y), length.out = np)
nd <- expand.grid(x = nd.x, y = nd.y)
prd <- as.numeric(predict(mdl, newdata = nd)$class)
plot(my.xyc[, 1:2], col = my.xyc$group)
contour(x = nd.x, y = nd.y, z = matrix(prd, nrow = np, ncol = np),
levels = c(1, 2), add = TRUE, drawlabels = FALSE)