Home > database >  Unable to plot my QDA classification method
Unable to plot my QDA classification method

Time:08-01

I have created a few types of classification, but when performing QDA I'm am unable to plot my predictions, does anyone know how to predict this?

set.seed(20220719)
#splitting training and testing data
ii = createDataPartition(classification[,3], p = .75, list = F)

training = classification[ii, ] #predictors for training testing = classification[-ii, ] #predictors for testing

#fitting the model
qda_mod = qda(Group ~., training)

#predicting testing data
p2 = predict(qda_mod, testing)$class
tab1 = table(Predicted = p2, Actual = testing$Group)
tab1

data snipet

classification
             X1           X2 Group
1   -1.007927175  0.399027128     0
2   -0.472479667  0.839121791     1
3    0.745229326 -1.279741933     1
4   -0.597907906 -1.942435976     1
5    0.186984091 -1.541910328     1
6   -0.395736986 -0.120650487     1
7   -0.155861012  1.193432933     0
8    0.382043985 -1.700433181     1
9    0.684346226 -0.890674936     1
10   0.453268993  0.674205724     1

Looking for an output similar to;

enter image description here

CodePudding user response:

The Predicted groups have been colored with actual classification with red and green color. These are extracted from your predict call. The mix of red and green colors in groups shows the incorrect classification prediction. You can use the following code:

library(caret)
library(MASS)
set.seed(20220719)
#splitting training and testing data
ii = createDataPartition(classification[,3], p = .75, list = F)

training = classification[ii, ] #predictors for training 
testing = classification[-ii, ] #predictors for testing

#fitting the model
qda_mod = qda(Group ~., training)

#predicting testing data
p2 = predict(qda_mod, testing)
#tab1 = table(Predicted = p2, Actual = testing$Group)
#tab1

# plot
par(mfrow=c(1,1))
plot(p2$posterior[,2], p2$class, col=testing$Group 10)

Output:

enter image description here

For extra info check this enter image description here

  • Related