train_qda <- train(y ~., method = "qda", data = train_set)
train_qda$finalModel
Call:
qda(x, grouping = y)
Prior probabilities of groups:
1 2 7
0.3641474 0.3123048 0.3235478
Group means:
x_1 x_2
1 0.07506762 0.2345093
2 0.12928502 0.2801805
7 0.24040191 0.2956395
y_hat_qda <- predict(train_qda, test_set)
confusionMatrix(data = y_hat_qda, reference = test_set$y)
Confusion Matrix and Statistics
Reference
Prediction 1 2 7
1 107 15 6
2 8 102 17
7 14 24 106
Overall Statistics
Accuracy : 0.7895
95% CI : (0.7461, 0.8285)
No Information Rate : 0.3534
P-Value [Acc > NIR] : < 2e-16
Kappa : 0.6844
Mcnemar's Test P-Value : 0.08866
Statistics by Class:
Class: 1 Class: 2 Class: 7
Sensitivity 0.8295 0.7234 0.8217
Specificity 0.9222 0.9031 0.8593
Pos Pred Value 0.8359 0.8031 0.7361
Neg Pred Value 0.9188 0.8566 0.9098
Prevalence 0.3233 0.3534 0.3233
Detection Rate 0.2682 0.2556 0.2657
Detection Prevalence 0.3208 0.3183 0.3609
Balanced Accuracy 0.8758 0.8133 0.8405
confusionMatrix(data = y_hat_qda, reference = test_set$y)$overall["Accuracy"]
y_hat_qda <- predict(train_qda, mnist_27$true_p)
y_hat_qda <- as.numeric(levels(y_hat_qda))[y_hat_qda]
options(repr.plot.width=7, repr.plot.height=7)
mnist_27$true_p %>%
mutate(y_hat = factor(y_hat_qda)) %>%
ggplot(aes(x_1, x_2, z=y_hat, fill=y_hat)) +
geom_raster()
train_lda <- train(y ~., method = "lda", data = train_set)
train_lda$finalModel
Call:
lda(x, grouping = y)
Prior probabilities of groups:
1 2 7
0.3641474 0.3123048 0.3235478
Group means:
x_1 x_2
1 0.07506762 0.2345093
2 0.12928502 0.2801805
7 0.24040191 0.2956395
Coefficients of linear discriminants:
LD1 LD2
x_1 12.790861 3.054090
x_2 -2.955191 -9.101932
Proportion of trace:
LD1 LD2
0.9832 0.0168
y_hat_lda <- predict(train_lda, test_set)
confusionMatrix(data = y_hat_lda, reference = test_set$y)
Confusion Matrix and Statistics
Reference
Prediction 1 2 7
1 100 70 8
2 14 43 17
7 15 28 104
Overall Statistics
Accuracy : 0.619
95% CI : (0.5694, 0.6669)
No Information Rate : 0.3534
P-Value [Acc > NIR] : < 2.2e-16
Kappa : 0.4324
Mcnemar's Test P-Value : 3.724e-09
Statistics by Class:
Class: 1 Class: 2 Class: 7
Sensitivity 0.7752 0.3050 0.8062
Specificity 0.7111 0.8798 0.8407
Pos Pred Value 0.5618 0.5811 0.7075
Neg Pred Value 0.8688 0.6985 0.9008
Prevalence 0.3233 0.3534 0.3233
Detection Rate 0.2506 0.1078 0.2607
Detection Prevalence 0.4461 0.1855 0.3684
Balanced Accuracy 0.7432 0.5924 0.8235
confusionMatrix(data = y_hat_lda, reference = test_set$y)$overall["Accuracy"]
y_hat_lda <- predict(train_lda, mnist_27$true_p)
y_hat_lda <- as.numeric(levels(y_hat_lda))[y_hat_lda]
mnist_27$true_p %>%
mutate(y_hat = factor(y_hat_lda)) %>%
ggplot(aes(x_1, x_2, z=y_hat, fill=y_hat)) +
geom_raster()
Checking on the confusion matrix of both methods we can see that the accuracy got a lot lower in both cases.
The following graphic shows the dataset with their estimated normal distribution, and we can see that the predictors does not follow bivariate normal distribution.