Brier Accuracy Kappa ROCAUC
NA 0.9666667 0.9500000 0.5250000
Brier Accuracy Kappa
0.06996853 0.96666667 0.95000000
An object of class "Resamples"
Models: RandomForestModel
Stratification variable: (strata)
An object from class "MLControl"
Name: CVControl
Label: K-Fold Cross-Validation
Folds: 5
Repeats: 3
Seed: 123
RandomForestModel :
Observed
Predicted Iris-setosa Iris-versicolor Iris-virginica
Iris-setosa 150 0 0
Iris-versicolor 0 141 16
Iris-virginica 0 9 134
RandomForestModel :
Accuracy Sensitivity Specificity
0.9444444 NA NA
RandomForestModel :
Number of responses: 450
Accuracy (SE): 0.9444444 (0.01079806)
Majority class: 0.3333333
Kappa: 0.9166667
Iris-setosa Iris-versicolor Iris-virginica
Observed 0.3333333 0.3333333 0.3333333
Predicted 0.3333333 0.3488889 0.3177778
Agreement 0.3333333 0.3133333 0.2977778
Sensitivity 1.0000000 0.9400000 0.8933333
Specificity 1.0000000 0.9466667 0.9700000
PPV 1.0000000 0.8980892 0.9370629
NPV 1.0000000 0.9692833 0.9478827
$RandomForestModel
Brier Accuracy Kappa ROCAUC
NA 0.900 0.850 0.575
Brier Accuracy Kappa
0.1857125 0.9000000 0.8500000
An object of class "Resamples"
Models: RPartModel
Stratification variable: (strata)
An object from class "MLControl"
Name: CVControl
Label: K-Fold Cross-Validation
Folds: 5
Repeats: 3
Seed: 123
RPartModel :
Observed
Predicted Iris-setosa Iris-versicolor Iris-virginica
Iris-setosa 150 0 0
Iris-versicolor 0 143 17
Iris-virginica 0 7 133
RPartModel :
Accuracy Sensitivity Specificity
0.9466667 NA NA
RPartModel :
Number of responses: 450
Accuracy (SE): 0.9466667 (0.01059233)
Majority class: 0.3333333
Kappa: 0.92
Iris-setosa Iris-versicolor Iris-virginica
Observed 0.3333333 0.3333333 0.3333333
Predicted 0.3333333 0.3555556 0.3111111
Agreement 0.3333333 0.3177778 0.2955556
Sensitivity 1.0000000 0.9533333 0.8866667
Specificity 1.0000000 0.9433333 0.9766667
PPV 1.0000000 0.8937500 0.9500000
NPV 1.0000000 0.9758621 0.9451613
$RPartModel
Brier Accuracy Kappa ROCAUC
NA 0.9333333 0.9000000 0.5500000
Brier Accuracy Kappa
0.05785324 0.93333333 0.90000000
An object of class "Resamples"
Models: KNNModel
Stratification variable: (strata)
An object from class "MLControl"
Name: CVControl
Label: K-Fold Cross-Validation
Folds: 5
Repeats: 3
Seed: 123
KNNModel :
Observed
Predicted Iris-setosa Iris-versicolor Iris-virginica
Iris-setosa 149 0 0
Iris-versicolor 1 140 13
Iris-virginica 0 10 137
KNNModel :
Accuracy Sensitivity Specificity
0.9466667 NA NA
KNNModel :
Number of responses: 450
Accuracy (SE): 0.9466667 (0.01059233)
Majority class: 0.3333333
Kappa: 0.92
Iris-setosa Iris-versicolor Iris-virginica
Observed 0.3333333 0.3333333 0.3333333
Predicted 0.3311111 0.3422222 0.3266667
Agreement 0.3311111 0.3111111 0.3044444
Sensitivity 0.9933333 0.9333333 0.9133333
Specificity 1.0000000 0.9533333 0.9666667
PPV 1.0000000 0.9090909 0.9319728
NPV 0.9966777 0.9662162 0.9570957
$KNNModel
---
title: "Iris Prediction Model Evaluation"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: [ "twitter", "facebook","menu" ]
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(MachineShop)
library(survival)
library(MASS)
library(magrittr)
library(gbm)
library(rpart)
library(partykit)
library(randomForest)
library(kknn)
library(caret)
```
```{r include=FALSE}
# attach the iris dataset
data(iris)
# rename the dataset
dataset <- iris
# define the filename
filename <- "iris.csv"
# load the CSV file from the local directory
surv_df <- read.csv(filename, header=FALSE)
# set the column names in the dataset
colnames(surv_df) <- c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species")
set.seed(123)
# create a list of 80% of the rows in the original dataset we can use for training
validation_index <- createDataPartition(surv_df$Species, p=0.80, list=FALSE)
# select 20% of the data for validation
surv_test <- surv_df[-validation_index,]
# use the remaining 80% of data to training and testing the models
surv_train <- surv_df[validation_index,]
## Global formula for the analysis
surv_fo <- Species ~ .
## All available models
# modelinfo() %>% names
## Model-specific information
# modelinfo(RandomForestModel)
## Control parameters for K-fold cross-validation
## Prediction of survival means
surv_means_control <- CVControl(folds = 5, repeats = 3, seed = 123)
## Prediction of survival probabilities
surv_probs_control <- CVControl(folds = 5, repeats = 3, seed = 123)
```
Random Forest Model
================
Row {.tabset .tabset-fade}
-------------------------
### Prediction of Means and Probability
```{r}
## Model function
surv_fit_RF <- fit(surv_fo, data = surv_train, model = RandomForestModel)
## Observed responses
obs <- response(surv_fo, surv_test)
## Predicted survival means
pred_means_RF <- predict(surv_fit_RF, newdata = surv_test)
performance(obs, pred_means_RF)
## Predicted survival probabilities
pred_probs_RF <- predict(surv_fit_RF, newdata = surv_test, type = "prob")
performance(obs, pred_probs_RF)
(res_probs_RF <- resample(surv_fo, data = surv_df, model = RandomForestModel, control = surv_probs_control))
```
### Performance Metrics
```{r}
## Confusion matrices
(conf_RF <- confusion(res_probs_RF, cutoff = 0.5))
performance(conf_RF, metrics = c("Accuracy" = accuracy,
"Sensitivity" = sensitivity,
"Specificity" = specificity))
```
### Confusion Matrix
```{r}
summary(conf_RF)
```
### Confusion Metrix Plot
```{r}
plot(conf_RF)
```
RPartModel
================
Row {.tabset .tabset-fade}
-------------------------
### Prediction of Means and Probability
```{r}
## Model function
surv_fit_RP <- fit(surv_fo, data = surv_train, model = RPartModel)
## Observed responses
obs <- response(surv_fo, surv_test)
## Predicted survival means
pred_means_RP <- predict(surv_fit_RP, newdata = surv_test)
performance(obs, pred_means_RP)
## Predicted survival probabilities
pred_probs_RP <- predict(surv_fit_RP, newdata = surv_test, type = "prob")
performance(obs, pred_probs_RP)
(res_probs_RP <- resample(surv_fo, data = surv_df, model = RPartModel, control = surv_probs_control))
```
### Performance Metrics
```{r}
## Confusion matrices
(conf_RP <- confusion(res_probs_RP, cutoff = 0.5))
performance(conf_RP, metrics = c("Accuracy" = accuracy,
"Sensitivity" = sensitivity,
"Specificity" = specificity))
```
### Confusion Matrix
```{r}
summary(conf_RP)
```
### Confusion Metrix Plot
```{r}
plot(conf_RP)
```
KNNModel
================
Row {.tabset .tabset-fade}
-------------------------
### Prediction of Means and Probability
```{r}
## Model function
surv_fit_knn <- fit(surv_fo, data = surv_train, model = KNNModel)
## Observed responses
obs <- response(surv_fo, surv_test)
## Predicted survival means
pred_means_knn <- predict(surv_fit_knn, newdata = surv_test)
performance(obs, pred_means_knn)
## Predicted survival probabilities
pred_probs_knn <- predict(surv_fit_knn, newdata = surv_test, type = "prob")
performance(obs, pred_probs_knn)
(res_probs_knn <- resample(surv_fo, data = surv_df, model = KNNModel, control = surv_probs_control))
```
### Performance Metrics
```{r}
## Confusion matrices
(conf_knn <- confusion(res_probs_knn, cutoff = 0.5))
performance(conf_knn, metrics = c("Accuracy" = accuracy,
"Sensitivity" = sensitivity,
"Specificity" = specificity))
```
### Confusion Matrix
```{r}
summary(conf_knn)
```
### Confusion Metrix Plot
```{r}
plot(conf_knn)
```