LOAD DATA & PREPROCESSING

df <- read.csv("balance-scale.data", header = FALSE)

Data dibaca dari file balance-scale.data menggunakan fungsi read.csv() tanpa header untuk digunakan dalam analisis selanjutnya.

colnames(df) <- c("class", "left_weight", "left_distance", "right_weight", "right_distance")

Memberikan nama kolom pada dataset agar lebih mudah dipahami.

df$class <- as.factor(df$class)

Mengubah variabel class menjadi tipe faktor untuk keperluan klasifikasi.

str(df)
## 'data.frame':    625 obs. of  5 variables:
##  $ class         : Factor w/ 3 levels "B","L","R": 1 3 3 3 3 3 3 3 3 3 ...
##  $ left_weight   : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ left_distance : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ right_weight  : int  1 1 1 1 1 2 2 2 2 2 ...
##  $ right_distance: int  1 2 3 4 5 1 2 3 4 5 ...

Menampilkan struktur data untuk melihat tipe dan isi setiap variabel.

table(df$class)
## 
##   B   L   R 
##  49 288 288

Menampilkan jumlah data pada masing-masing kelas.

summary(df)
##  class    left_weight left_distance  right_weight right_distance
##  B: 49   Min.   :1    Min.   :1     Min.   :1     Min.   :1     
##  L:288   1st Qu.:2    1st Qu.:2     1st Qu.:2     1st Qu.:2     
##  R:288   Median :3    Median :3     Median :3     Median :3     
##          Mean   :3    Mean   :3     Mean   :3     Mean   :3     
##          3rd Qu.:4    3rd Qu.:4     3rd Qu.:4     3rd Qu.:4     
##          Max.   :5    Max.   :5     Max.   :5     Max.   :5

Menampilkan ringkasan statistik deskriptif dari setiap variabel.

SPLIT DATA

set.seed(123)
index <- sample(1:nrow(df), 0.7 * nrow(df))

Membuat indeks acak untuk membagi data menjadi data latih (70%).

train <- df[index, ]
test  <- df[-index, ]

Membagi data menjadi data latih dan data uji.

UJI ASUMSI

install.packages("MVN")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)

Menginstal package MVN untuk uji normalitas multivariat.

library(MVN)
## Registered S3 method overwritten by 'lme4':
##   method           from
##   na.action.merMod car

Memanggil package MVN.

mvn_result <- MVN::mvn(
  data = train[, -1],
  mvn_test = "mardia"
)

Melakukan uji normalitas multivariat menggunakan metode Mardia.

mvn_result
## $multivariate_normality
##              Test Statistic p.value     Method          MVN
## 1 Mardia Skewness     2.125       1 asymptotic     ✓ Normal
## 2 Mardia Kurtosis    -7.898  <0.001 asymptotic ✗ Not normal
## 
## $univariate_normality
##               Test       Variable Statistic p.value    Normality
## 1 Anderson-Darling    left_weight    15.994  <0.001 ✗ Not normal
## 2 Anderson-Darling  left_distance    15.606  <0.001 ✗ Not normal
## 3 Anderson-Darling   right_weight    15.249  <0.001 ✗ Not normal
## 4 Anderson-Darling right_distance    16.562  <0.001 ✗ Not normal
## 
## $descriptives
##         Variable   n  Mean Std.Dev Median Min Max 25th 75th   Skew Kurtosis
## 1    left_weight 437 2.938   1.420      3   1   5    2    4  0.071    1.692
## 2  left_distance 437 3.032   1.406      3   1   5    2    4 -0.007    1.706
## 3   right_weight 437 3.011   1.407      3   1   5    2    4 -0.015    1.725
## 4 right_distance 437 3.057   1.432      3   1   5    2    4 -0.077    1.668
## 
## $data
##     left_weight left_distance right_weight right_distance
## 415           4             2            3              5
## 463           4             4            3              3
## 179           2             3            1              4
## 526           5             2            1              1
## 195           2             3            4              5
## 118           1             5            4              3
## 299           3             2            5              4
## 229           2             5            1              4
## 244           2             5            4              4
## 14            1             1            3              4
## 374           3             5            5              4
## 602           5             5            1              2
## 603           5             5            1              3
## 91            1             4            4              1
## 348           3             4            5              3
## 355           3             5            1              5
## 26            1             2            1              1
## 519           5             1            4              4
## 426           4             3            1              1
## 211           2             4            3              1
## 590           5             4            3              5
## 593           5             4            4              3
## 555           5             3            1              5
## 373           3             5            5              3
## 143           2             1            4              3
## 544           5             2            4              4
## 490           4             5            3              5
## 23            1             1            5              3
## 309           3             3            2              4
## 135           2             1            2              5
## 224           2             4            5              4
## 166           2             2            4              1
## 217           2             4            4              2
## 290           3             2            3              5
## 581           5             4            2              1
## 72            1             3            5              2
## 588           5             4            3              3
## 575           5             3            5              5
## 141           2             1            4              1
## 153           2             2            1              3
## 294           3             2            4              4
## 277           3             2            1              2
## 624           5             5            5              4
## 41            1             2            4              1
## 431           4             3            2              1
## 90            1             4            3              5
## 316           3             3            4              1
## 223           2             4            5              3
## 528           5             2            1              3
## 116           1             5            4              1
## 456           4             4            2              1
## 39            1             2            3              4
## 159           2             2            2              4
## 209           2             4            2              4
## 615           5             5            3              5
## 34            1             2            2              4
## 516           5             1            4              1
## 13            1             1            3              3
## 69            1             3            4              4
## 409           4             2            2              4
## 308           3             3            2              3
## 278           3             2            1              3
## 89            1             4            3              4
## 537           5             2            3              2
## 291           3             2            4              1
## 424           4             2            5              4
## 286           3             2            3              1
## 121           1             5            5              1
## 110           1             5            2              5
## 158           2             2            2              3
## 64            1             3            3              4
## 483           4             5            2              3
## 477           4             5            1              2
## 480           4             5            1              5
## 67            1             3            4              2
## 85            1             4            2              5
## 165           2             2            3              5
## 51            1             3            1              1
## 74            1             3            5              4
## 178           2             3            1              3
## 362           3             5            3              2
## 236           2             5            3              1
## 330           3             4            1              5
## 127           2             1            1              2
## 212           2             4            3              2
## 310           3             3            2              5
## 243           2             5            4              3
## 113           1             5            3              3
## 553           5             3            1              3
## 151           2             2            1              1
## 160           2             2            2              5
## 391           4             1            4              1
## 155           2             2            1              5
## 607           5             5            2              2
## 5             1             1            1              5
## 326           3             4            1              1
## 280           3             2            1              5
## 238           2             5            3              3
## 339           3             4            3              4
## 574           5             3            5              4
## 137           2             1            3              2
## 455           4             4            1              5
## 83            1             4            2              3
## 622           5             5            5              2
## 196           2             3            5              1
## 559           5             3            2              4
## 500           4             5            5              5
## 344           3             4            4              4
## 540           5             2            3              5
## 459           4             4            2              4
## 20            1             1            4              5
## 621           5             5            5              1
## 164           2             2            3              4
## 52            1             3            1              2
## 364           3             5            3              4
## 22            1             1            5              2
## 177           2             3            1              2
## 42            1             2            4              2
## 315           3             3            3              5
## 84            1             4            2              4
## 11            1             1            3              1
## 558           5             3            2              3
## 439           4             3            3              4
## 392           4             1            4              2
## 302           3             3            1              2
## 550           5             2            5              5
## 365           3             5            3              5
## 194           2             3            4              4
## 107           1             5            2              2
## 77            1             4            1              2
## 430           4             3            1              5
## 198           2             3            5              3
## 249           2             5            5              4
## 200           2             3            5              5
## 428           4             3            1              3
## 535           5             2            2              5
## 250           2             5            5              5
## 292           3             2            4              2
## 429           4             3            1              4
## 398           4             1            5              3
## 16            1             1            4              1
## 471           4             4            5              1
## 381           4             1            2              1
## 33            1             2            2              3
## 40            1             2            3              5
## 560           5             3            2              5
## 10            1             1            2              5
## 473           4             4            5              3
## 492           4             5            4              2
## 466           4             4            4              1
## 125           1             5            5              5
## 265           3             1            3              5
## 263           3             1            3              3
## 534           5             2            2              4
## 186           2             3            3              1
## 61            1             3            3              1
## 252           3             1            1              2
## 458           4             4            2              3
## 152           2             2            1              2
## 319           3             3            4              4
## 54            1             3            1              4
## 407           4             2            2              2
## 609           5             5            2              4
## 235           2             5            2              5
## 289           3             2            3              4
## 185           2             3            2              5
## 253           3             1            1              3
## 413           4             2            3              3
## 115           1             5            3              5
## 479           4             5            1              4
## 597           5             4            5              2
## 465           4             4            3              5
## 205           2             4            1              5
## 363           3             5            3              3
## 267           3             1            4              2
## 25            1             1            5              5
## 512           5             1            3              2
## 282           3             2            2              2
## 472           4             4            5              2
## 566           5             3            4              1
## 215           2             4            3              5
## 346           3             4            5              1
## 599           5             4            5              4
## 408           4             2            2              3
## 57            1             3            2              2
## 105           1             5            1              5
## 357           3             5            2              2
## 279           3             2            1              4
## 270           3             1            4              5
## 366           3             5            4              1
## 134           2             1            2              4
## 347           3             4            5              2
## 129           2             1            1              4
## 218           2             4            4              3
## 106           1             5            2              1
## 369           3             5            4              4
## 484           4             5            2              4
## 337           3             4            3              2
## 285           3             2            2              5
## 583           5             4            2              3
## 27            1             2            1              2
## 7             1             1            2              2
## 245           2             5            4              5
## 154           2             2            1              4
## 582           5             4            2              2
## 541           5             2            4              1
## 390           4             1            3              5
## 222           2             4            5              2
## 573           5             3            5              3
## 349           3             4            5              4
## 145           2             1            4              5
## 441           4             3            4              1
## 148           2             1            5              3
## 163           2             2            3              3
## 577           5             4            1              2
## 161           2             2            3              1
## 66            1             3            4              1
## 4             1             1            1              4
## 543           5             2            4              3
## 225           2             4            5              5
## 389           4             1            3              4
## 117           1             5            4              2
## 450           4             3            5              5
## 136           2             1            3              1
## 55            1             3            1              5
## 604           5             5            1              4
## 608           5             5            2              3
## 45            1             2            4              5
## 146           2             1            5              1
## 170           2             2            4              5
## 435           4             3            2              5
## 199           2             3            5              4
## 361           3             5            3              1
## 176           2             3            1              1
## 423           4             2            5              3
## 524           5             1            5              4
## 104           1             5            1              4
## 419           4             2            4              4
## 476           4             5            1              1
## 394           4             1            4              4
## 210           2             4            2              5
## 416           4             2            4              1
## 406           4             2            2              1
## 258           3             1            2              3
## 509           5             1            2              4
## 587           5             4            3              2
## 24            1             1            5              4
## 130           2             1            1              5
## 549           5             2            5              4
## 191           2             3            4              1
## 76            1             4            1              1
## 269           3             1            4              4
## 396           4             1            5              1
## 494           4             5            4              4
## 545           5             2            4              5
## 234           2             5            2              4
## 368           3             5            4              3
## 613           5             5            3              3
## 80            1             4            1              5
## 36            1             2            3              1
## 561           5             3            3              1
## 569           5             3            4              4
## 343           3             4            4              3
## 323           3             3            5              3
## 48            1             2            5              3
## 111           1             5            3              1
## 438           4             3            3              3
## 317           3             3            4              2
## 295           3             2            4              5
## 418           4             2            4              3
## 287           3             2            3              2
## 356           3             5            2              1
## 73            1             3            5              3
## 488           4             5            3              3
## 226           2             5            1              1
## 564           5             3            3              4
## 172           2             2            5              2
## 297           3             2            5              2
## 93            1             4            4              3
## 475           4             4            5              5
## 619           5             5            4              4
## 522           5             1            5              2
## 237           2             5            3              2
## 377           4             1            1              2
## 497           4             5            5              2
## 482           4             5            2              2
## 523           5             1            5              3
## 584           5             4            2              4
## 572           5             3            5              2
## 375           3             5            5              5
## 94            1             4            4              4
## 499           4             5            5              4
## 30            1             2            1              5
## 400           4             1            5              5
## 175           2             2            5              5
## 371           3             5            5              1
## 457           4             4            2              2
## 96            1             4            5              1
## 614           5             5            3              4
## 328           3             4            1              3
## 532           5             2            2              2
## 230           2             5            1              5
## 468           4             4            4              3
## 202           2             4            1              2
## 81            1             4            2              1
## 232           2             5            2              2
## 539           5             2            3              4
## 591           5             4            4              1
## 505           5             1            1              5
## 538           5             2            3              3
## 380           4             1            1              5
## 31            1             2            2              1
## 329           3             4            1              4
## 350           3             4            5              5
## 335           3             4            2              5
## 322           3             3            5              2
## 485           4             5            2              5
## 197           2             3            5              2
## 546           5             2            5              1
## 554           5             3            1              4
## 12            1             1            3              2
## 446           4             3            5              1
## 50            1             2            5              5
## 204           2             4            1              4
## 331           3             4            2              1
## 395           4             1            4              5
## 122           1             5            5              2
## 259           3             1            2              4
## 248           2             5            5              3
## 461           4             4            3              1
## 393           4             1            4              3
## 100           1             4            5              5
## 108           1             5            2              3
## 589           5             4            3              4
## 327           3             4            1              2
## 529           5             2            1              4
## 491           4             5            4              1
## 525           5             1            5              5
## 293           3             2            4              3
## 8             1             1            2              3
## 114           1             5            3              4
## 261           3             1            3              1
## 29            1             2            1              4
## 547           5             2            5              2
## 353           3             5            1              3
## 451           4             4            1              1
## 262           3             1            3              2
## 595           5             4            4              5
## 501           5             1            1              1
## 606           5             5            2              1
## 219           2             4            4              4
## 184           2             3            2              4
## 533           5             2            2              3
## 119           1             5            4              4
## 551           5             3            1              1
## 557           5             3            2              2
## 300           3             2            5              5
## 436           4             3            3              1
## 401           4             2            1              1
## 240           2             5            3              5
## 120           1             5            4              5
## 352           3             5            1              2
## 586           5             4            3              1
## 585           5             4            2              5
## 440           4             3            3              5
## 180           2             3            1              5
## 241           2             5            4              1
## 379           4             1            1              4
## 167           2             2            4              2
## 47            1             2            5              2
## 188           2             3            3              3
## 376           4             1            1              1
## 37            1             2            3              2
## 174           2             2            5              4
## 454           4             4            1              4
## 256           3             1            2              1
## 207           2             4            2              2
## 144           2             1            4              4
## 19            1             1            4              4
## 562           5             3            3              2
## 417           4             2            4              2
## 345           3             4            4              5
## 511           5             1            3              1
## 103           1             5            1              3
## 503           5             1            1              3
## 255           3             1            1              5
## 190           2             3            3              5
## 208           2             4            2              3
## 288           3             2            3              3
## 139           2             1            3              4
## 43            1             2            4              3
## 313           3             3            3              3
## 556           5             3            2              1
## 189           2             3            3              4
## 517           5             1            4              2
## 592           5             4            4              2
## 320           3             3            4              5
## 162           2             2            3              2
## 414           4             2            3              4
## 126           2             1            1              1
## 38            1             2            3              3
## 506           5             1            2              1
## 63            1             3            3              3
## 469           4             4            4              4
## 78            1             4            1              3
## 70            1             3            4              5
## 397           4             1            5              2
## 378           4             1            1              3
## 474           4             4            5              4
## 246           2             5            5              1
## 75            1             3            5              5
## 21            1             1            5              1
## 460           4             4            2              5
## 386           4             1            3              1
## 87            1             4            3              2
## 605           5             5            1              5
## 59            1             3            2              4
## 231           2             5            2              1
## 342           3             4            4              2
## 321           3             3            5              1
## 324           3             3            5              4
## 571           5             3            5              1
## 168           2             2            4              3
## 6             1             1            2              1
## 128           2             1            1              3
## 360           3             5            2              5
## 156           2             2            2              1
## 32            1             2            2              2
## 49            1             2            5              4
## 312           3             3            3              2
## 193           2             3            4              3
## 489           4             5            3              4
## 464           4             4            3              4
## 432           4             3            2              2
## 239           2             5            3              4
## 112           1             5            3              2
## 272           3             1            5              2
## 
## $subset
## NULL
## 
## $outlierMethod
## [1] "none"
## 
## attr(,"class")
## [1] "mvn"

Menampilkan hasil uji normalitas multivariat.

install.packages("biotools")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)

Menginstal package biotools untuk uji homogenitas.

library(biotools)
## Loading required package: MASS
## ---
## biotools version 4.3

Memanggil package biotools.

boxm_result <- boxM(train[, -1], train$class)

Melakukan uji homogenitas kovarians menggunakan Box’s M Test.

boxm_result
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  train[, -1]
## Chi-Sq (approx.) = 104.06, df = 20, p-value = 2.349e-13

Menampilkan hasil uji homogenitas kovarians.

install.packages("corrplot")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)

Menginstal package corrplot untuk visualisasi korelasi.

library(corrplot)
## corrplot 0.95 loaded

Memanggil package corrplot.

cor_matrix <- cor(train[, -1])
corrplot(cor_matrix, method = "number")

Menghitung dan menampilkan matriks korelasi antar variabel.

install.packages("car")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)

Menginstal package car untuk uji multikolinearitas.

library(car)
## Loading required package: carData

Memanggil package car.

model_vif <- lm(left_weight ~ left_distance + right_weight + right_distance, data = train)
vif(model_vif)
##  left_distance   right_weight right_distance 
##       1.001310       1.000511       1.001559

Menghitung nilai VIF untuk mendeteksi multikolinearitas.

dev.off()
## null device 
##           1
par(mar = c(4,4,2,1))
boxplot(train[, -1], main = "Boxplot Variabel")

Menampilkan boxplot untuk mendeteksi outlier pada data.

UJI INDEPENDENSI

contingency_table <- table(train$class, train$left_weight)

Membuat tabel kontingensi antara variabel class dan left_weight.

chi_sq_result <- chisq.test(contingency_table)

Melakukan uji Chi-Square untuk menguji independensi variabel.

chi_sq_result
## 
##  Pearson's Chi-squared test
## 
## data:  contingency_table
## X-squared = 84.338, df = 8, p-value = 6.52e-15

Menampilkan hasil uji independensi.

ANALISIS DISKRIMINAN(LDA)

install.packages("MASS")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)

Menginstal package MASS untuk analisis diskriminan.

library(MASS)

Memanggil package MASS.

model_lda <- lda(class ~ ., data = train)

Membangun model Linear Discriminant Analysis (LDA).

model_lda
## Call:
## lda(class ~ ., data = train)
## 
## Prior probabilities of groups:
##          B          L          R 
## 0.07551487 0.45308924 0.47139588 
## 
## Group means:
##   left_weight left_distance right_weight right_distance
## B    3.030303      2.969697     3.030303       3.030303
## L    3.580808      3.606061     2.368687       2.454545
## R    2.305825      2.490291     3.626214       3.640777
## 
## Coefficients of linear discriminants:
##                       LD1         LD2
## left_weight     0.6279509  0.50466344
## left_distance   0.5917508 -0.44917839
## right_weight   -0.6539825  0.18146589
## right_distance -0.6116543 -0.07225013
## 
## Proportion of trace:
##    LD1    LD2 
## 0.9998 0.0002
model_lda$prior
##          B          L          R 
## 0.07551487 0.45308924 0.47139588
model_lda$means
##   left_weight left_distance right_weight right_distance
## B    3.030303      2.969697     3.030303       3.030303
## L    3.580808      3.606061     2.368687       2.454545
## R    2.305825      2.490291     3.626214       3.640777

Menampilkan informasi model LDA, prior, dan rata-rata tiap kelas

pred_lda <- predict(model_lda, test)

Melakukan prediksi menggunakan model LDA.

hasil_lda <- pred_lda$class

Mengambil hasil klasifikasi dari model LDA.

cm_lda <- table(Prediksi = hasil_lda, Aktual = test$class)
cm_lda
##         Aktual
## Prediksi  B  L  R
##        B  0  0  0
##        L 12 86  5
##        R  4  4 77

Membuat confusion matrix untuk evaluasi model LDA.

acc_lda <- mean(hasil_lda == test$class)
acc_lda
## [1] 0.8670213

Menghitung akurasi model LDA.

REGRESI LOGISTIK MULTINOMIAL

install.packages("nnet")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)

Menginstal package nnet untuk regresi logistik multinomial.

library(nnet)

Memanggil package nnet.

model_multi <- multinom(class ~ ., data = train)
## # weights:  18 (10 variable)
## initial  value 480.093570 
## iter  10 value 129.927118
## iter  20 value 108.661294
## iter  30 value 108.660701
## final  value 108.660693 
## converged

Membangun model regresi logistik multinomial.

summary(model_multi)
## Call:
## multinom(formula = class ~ ., data = train)
## 
## Coefficients:
##   (Intercept) left_weight left_distance right_weight right_distance
## L    0.282566    2.487433      2.528075    -2.639700      -2.505189
## R   -0.760835   -2.352174     -2.136474     2.392945       2.275570
## 
## Std. Errors:
##   (Intercept) left_weight left_distance right_weight right_distance
## L    1.045093   0.4731470     0.4711749    0.4852799      0.4656028
## R    1.071423   0.4186127     0.4043911    0.4387926      0.4211602
## 
## Residual Deviance: 217.3214 
## AIC: 237.3214

Menampilkan ringkasan hasil model regresi.

z <- summary(model_multi)$coefficients / summary(model_multi)$standard.errors
p_value <- (1 - pnorm(abs(z), 0, 1)) * 2
p_value
##   (Intercept)  left_weight left_distance right_weight right_distance
## L   0.7868724 1.462577e-07  8.073908e-08 5.341799e-08   7.426758e-08
## R   0.4776320 1.920935e-08  1.269554e-07 4.939459e-08   6.549890e-08

Menghitung nilai p-value untuk menguji signifikansi variabel.

pred_multi <- predict(model_multi, test)

Melakukan prediksi menggunakan model multinomial.

cm_multi <- table(Prediksi = pred_multi, Aktual = test$class)
cm_multi
##         Aktual
## Prediksi  B  L  R
##        B  4  2  5
##        L  9 86  2
##        R  3  2 75

Membuat confusion matrix untuk model multinomial.

acc_multi <- mean(pred_multi == test$class)
acc_multi
## [1] 0.8776596

Menghitung akurasi model multinomial.

EVALUASI

install.packages("caret")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)

Menginstal package caret untuk evaluasi model.

library(caret)
## Loading required package: ggplot2
## Loading required package: lattice

Memanggil package caret.

confusionMatrix(hasil_lda, test$class)
## Confusion Matrix and Statistics
## 
##           Reference
## Prediction  B  L  R
##          B  0  0  0
##          L 12 86  5
##          R  4  4 77
## 
## Overall Statistics
##                                         
##                Accuracy : 0.867         
##                  95% CI : (0.81, 0.9121)
##     No Information Rate : 0.4787        
##     P-Value [Acc > NIR] : < 2.2e-16     
##                                         
##                   Kappa : 0.754         
##                                         
##  Mcnemar's Test P-Value : 0.001076      
## 
## Statistics by Class:
## 
##                      Class: B Class: L Class: R
## Sensitivity           0.00000   0.9556   0.9390
## Specificity           1.00000   0.8265   0.9245
## Pos Pred Value            NaN   0.8350   0.9059
## Neg Pred Value        0.91489   0.9529   0.9515
## Prevalence            0.08511   0.4787   0.4362
## Detection Rate        0.00000   0.4574   0.4096
## Detection Prevalence  0.00000   0.5479   0.4521
## Balanced Accuracy     0.50000   0.8910   0.9318

Menampilkan evaluasi lengkap model LDA.

confusionMatrix(pred_multi, test$class)
## Confusion Matrix and Statistics
## 
##           Reference
## Prediction  B  L  R
##          B  4  2  5
##          L  9 86  2
##          R  3  2 75
## 
## Overall Statistics
##                                           
##                Accuracy : 0.8777          
##                  95% CI : (0.8221, 0.9208)
##     No Information Rate : 0.4787          
##     P-Value [Acc > NIR] : <2e-16          
##                                           
##                   Kappa : 0.7825          
##                                           
##  Mcnemar's Test P-Value : 0.1752          
## 
## Statistics by Class:
## 
##                      Class: B Class: L Class: R
## Sensitivity           0.25000   0.9556   0.9146
## Specificity           0.95930   0.8878   0.9528
## Pos Pred Value        0.36364   0.8866   0.9375
## Neg Pred Value        0.93220   0.9560   0.9352
## Prevalence            0.08511   0.4787   0.4362
## Detection Rate        0.02128   0.4574   0.3989
## Detection Prevalence  0.05851   0.5160   0.4255
## Balanced Accuracy     0.60465   0.9217   0.9337

Menampilkan evaluasi lengkap model multinomial.

PERBANDINGAN HASIL

cat("Akurasi LDA:", acc_lda, "\n")
## Akurasi LDA: 0.8670213
cat("Akurasi Multinomial:", acc_multi, "\n")
## Akurasi Multinomial: 0.8776596

Membandingkan akurasi kedua model.