library(mlbench)
## Warning: package 'mlbench' was built under R version 4.4.3
library(caret)
## Warning: package 'caret' was built under R version 4.4.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.4.3
## Loading required package: lattice
library(lattice)

data(PimaIndiansDiabetes)
dataset <- PimaIndiansDiabetes

trainControl <- trainControl(method = "repeatedcv", number = 10, repeats = 3)
set.seed(7)

fit.cart <- train(diabetes~., data=dataset, method="rpart", trControl=trainControl)
fit.lda  <- train(diabetes~., data=dataset, method="lda", trControl=trainControl)
fit.svm  <- train(diabetes~., data=dataset, method="svmRadial", trControl=trainControl)
fit.knn  <- train(diabetes~., data=dataset, method="knn", trControl=trainControl)
fit.rf   <- train(diabetes~., data=dataset, method="rf", trControl=trainControl)

results <- resamples(list(CART=fit.cart, LDA=fit.lda, SVM=fit.svm, KNN=fit.knn, RF=fit.rf))

summary(results)
## 
## Call:
## summary.resamples(object = results)
## 
## Models: CART, LDA, SVM, KNN, RF 
## Number of resamples: 30 
## 
## Accuracy 
##           Min.   1st Qu.    Median      Mean   3rd Qu.      Max. NA's
## CART 0.6753247 0.7272727 0.7532468 0.7469697 0.7662338 0.7922078    0
## LDA  0.7105263 0.7532468 0.7662338 0.7755867 0.8051948 0.8441558    0
## SVM  0.6623377 0.7245813 0.7582023 0.7604295 0.8000256 0.8571429    0
## KNN  0.6710526 0.7166353 0.7272727 0.7382319 0.7500000 0.8311688    0
## RF   0.6883117 0.7402597 0.7662338 0.7691274 0.8051948 0.8421053    0
## 
## Kappa 
##           Min.   1st Qu.    Median      Mean   3rd Qu.      Max. NA's
## CART 0.2762566 0.3620724 0.4241878 0.4151867 0.4861107 0.5250000    0
## LDA  0.2996968 0.4131568 0.4614831 0.4791233 0.5429981 0.6357827    0
## SVM  0.1740924 0.3557056 0.4112320 0.4338005 0.5261585 0.6602487    0
## KNN  0.2484177 0.3406000 0.3866611 0.4017113 0.4353306 0.6260740    0
## RF   0.3036925 0.4070045 0.4562480 0.4770543 0.5531915 0.6286645    0
scales <- list(x = list(relation="free"), y = list(relation="free"))
bwplot(results, scales=scales)

densityplot(results, scales=scales, pch = "|")

dotplot(results, scales=scales)

splom(results)

diffs <- diff(results)
summary(diffs)
## 
## Call:
## summary.diff.resamples(object = diffs)
## 
## p-value adjustment: bonferroni 
## Upper diagonal: estimates of the difference
## Lower diagonal: p-value for H0: difference = 0
## 
## Accuracy 
##      CART     LDA       SVM       KNN       RF       
## CART          -0.028617 -0.013460  0.008738 -0.022158
## LDA  0.028794            0.015157  0.037355  0.006459
## SVM  1.000000 1.000000             0.022198 -0.008698
## KNN  1.000000 0.001726  0.624760            -0.030895
## RF   0.362334 1.000000  1.000000  0.052505           
## 
## Kappa 
##      CART    LDA       SVM       KNN       RF       
## CART         -0.063937 -0.018614  0.013475 -0.061868
## LDA  0.03352            0.045323  0.077412  0.002069
## SVM  1.00000 1.00000              0.032089 -0.043254
## KNN  1.00000 0.01666   1.00000             -0.075343
## RF   0.14265 1.00000   1.00000   0.02578

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.