0

I have this

library(MASS)
mydata.qda <- qda(Sp ~ ., prior = c(1,1,1)/3, data = mydata.learn)

I would like to plot my results like http://scikit-learn.org/0.10/auto_examples/plot_lda_vs_qda.html

sonia
  • 167
  • 2
  • 2
  • 10
  • What do you expect to plot? You can draw a plot and color the points given the predicted class based on discriminant analysis. The command would be `plot(Sp ~ somevariable, data = mydata.learn, col = predict(mydata.qda)$class)`. There are a few examples of `qda` on teh internetz. [Here is one](http://statweb.stanford.edu/~jtaylo/courses/stats202/lda.html). – Roman Luštrik Feb 24 '15 at 15:00
  • But this have something in python or no? I want similar but only in R – sonia Feb 24 '15 at 15:27

2 Answers2

0

You should explain what you want to plot , here are some examples

https://tgmstat.wordpress.com/2014/01/15/computing-and-visualizing-lda-in-r/ http://www.statmethods.net/advstats/discriminant.html

in case you post an example data and say what you want to plot, you can get more help

0

You can plot the line that discriminates between clusters using contour. Here's an example. I made it following 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)

enter image description here

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197