Load the dataset and appropriate packages

library(readxl)
df<-read_xlsx("labW9.xlsx")

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(lattice)
library(caret)
library(klaR)
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
library(MASS)
library(e1071)
library(caTools)

Data exploration

str(df)
## tibble [768 x 9] (S3: tbl_df/tbl/data.frame)
##  $ Pregnancies             : num [1:768] 6 1 8 1 0 5 3 10 2 8 ...
##  $ Glucose                 : num [1:768] 148 85 183 89 137 116 78 115 197 125 ...
##  $ BloodPressure           : num [1:768] 72 66 64 66 40 74 50 0 70 96 ...
##  $ SkinThickness           : num [1:768] 35 29 0 23 35 0 32 0 45 0 ...
##  $ Insulin                 : num [1:768] 0 0 0 94 168 0 88 0 543 0 ...
##  $ BMI                     : num [1:768] 33.6 26.6 23.3 28.1 43.1 25.6 31 35.3 30.5 0 ...
##  $ DiabetesPedigreeFunction: num [1:768] 0.627 0.351 0.672 0.167 2.288 ...
##  $ Age                     : num [1:768] 50 31 32 21 33 30 26 29 53 54 ...
##  $ Outcome                 : num [1:768] 1 0 1 0 1 0 1 0 1 1 ...
summary(df)
##   Pregnancies        Glucose      BloodPressure    SkinThickness  
##  Min.   : 0.000   Min.   :  0.0   Min.   :  0.00   Min.   : 0.00  
##  1st Qu.: 1.000   1st Qu.: 99.0   1st Qu.: 62.00   1st Qu.: 0.00  
##  Median : 3.000   Median :117.0   Median : 72.00   Median :23.00  
##  Mean   : 3.845   Mean   :120.9   Mean   : 69.11   Mean   :20.54  
##  3rd Qu.: 6.000   3rd Qu.:140.2   3rd Qu.: 80.00   3rd Qu.:32.00  
##  Max.   :17.000   Max.   :199.0   Max.   :122.00   Max.   :99.00  
##     Insulin           BMI        DiabetesPedigreeFunction      Age       
##  Min.   :  0.0   Min.   : 0.00   Min.   :0.0780           Min.   :21.00  
##  1st Qu.:  0.0   1st Qu.:27.30   1st Qu.:0.2437           1st Qu.:24.00  
##  Median : 30.5   Median :32.00   Median :0.3725           Median :29.00  
##  Mean   : 79.8   Mean   :31.99   Mean   :0.4719           Mean   :33.24  
##  3rd Qu.:127.2   3rd Qu.:36.60   3rd Qu.:0.6262           3rd Qu.:41.00  
##  Max.   :846.0   Max.   :67.10   Max.   :2.4200           Max.   :81.00  
##     Outcome     
##  Min.   :0.000  
##  1st Qu.:0.000  
##  Median :0.000  
##  Mean   :0.349  
##  3rd Qu.:1.000  
##  Max.   :1.000
#The dataset contains 768 entries with 9 features.
#The feature 'Outcome' is the target variable (dependent variable).

Checking if data cleaning is necessary

colSums(is.na(df))
##              Pregnancies                  Glucose            BloodPressure 
##                        0                        0                        0 
##            SkinThickness                  Insulin                      BMI 
##                        0                        0                        0 
## DiabetesPedigreeFunction                      Age                  Outcome 
##                        0                        0                        0
#Since there is no any missing value in each feature, data cleaning is not required.

Convert column ‘Outcome’ into factor before proceed to modeling

df$Outcome <- as.factor(df$Outcome) #to ease the modeling process

#Checking the class for 'Outcome'
glimpse(df$Outcome)
##  Factor w/ 2 levels "0","1": 2 1 2 1 2 1 2 1 2 2 ...

Partition data into training and testing set by 70/30

#set random number
set.seed(168)
split = 0.7
trainIndex <- createDataPartition(df$Outcome, p=split, list = FALSE)
data_train <- df[trainIndex, ]
data_test <- df[-trainIndex, ]

#Check the dimension of both training and test subsets
dim(data_train)
## [1] 538   9
dim(data_test)
## [1] 230   9
#training set contains 538 entries while testing test contains 230 entries

Check for cross validation by different methods

#Repeated k fold sample 
df_train_control_1<-  trainControl(method='repeatedcv', number = 10, repeats = 3)
nbmodel1 <- train(Outcome~., data=data_train, trControl=df_train_control_1, method='nb')
print(nbmodel1)
## Naive Bayes 
## 
## 538 samples
##   8 predictor
##   2 classes: '0', '1' 
## 
## No pre-processing
## Resampling: Cross-Validated (10 fold, repeated 3 times) 
## Summary of sample sizes: 484, 484, 484, 485, 485, 484, ... 
## Resampling results across tuning parameters:
## 
##   usekernel  Accuracy   Kappa    
##   FALSE      0.7502562  0.4398002
##    TRUE      0.7521663  0.4499119
## 
## Tuning parameter 'fL' was held constant at a value of 0
## Tuning
##  parameter 'adjust' was held constant at a value of 1
## Accuracy was used to select the optimal model using the largest value.
## The final values used for the model were fL = 0, usekernel = TRUE and adjust
##  = 1.
#Leave one out CV sample 
df_train_control_2 <- trainControl(method = 'LOOCV')
nbmodel2 <- train(Outcome~., data=data_train, trControl=df_train_control_2, method='nb')
print(nbmodel2)
## Naive Bayes 
## 
## 538 samples
##   8 predictor
##   2 classes: '0', '1' 
## 
## No pre-processing
## Resampling: Leave-One-Out Cross-Validation 
## Summary of sample sizes: 537, 537, 537, 537, 537, 537, ... 
## Resampling results across tuning parameters:
## 
##   usekernel  Accuracy   Kappa    
##   FALSE      0.7490706  0.4391246
##    TRUE      0.7546468  0.4576944
## 
## Tuning parameter 'fL' was held constant at a value of 0
## Tuning
##  parameter 'adjust' was held constant at a value of 1
## Accuracy was used to select the optimal model using the largest value.
## The final values used for the model were fL = 0, usekernel = TRUE and adjust
##  = 1.
#Bootstrap sample 
df_train_control_3 <- trainControl(method='boot', number=100)
nbmodel3<- train(Outcome~., data=data_train, trControl=df_train_control_3, method='nb')
print(nbmodel3)
## Naive Bayes 
## 
## 538 samples
##   8 predictor
##   2 classes: '0', '1' 
## 
## No pre-processing
## Resampling: Bootstrapped (100 reps) 
## Summary of sample sizes: 538, 538, 538, 538, 538, 538, ... 
## Resampling results across tuning parameters:
## 
##   usekernel  Accuracy   Kappa    
##   FALSE      0.7535646  0.4479311
##    TRUE      0.7528664  0.4520643
## 
## Tuning parameter 'fL' was held constant at a value of 0
## Tuning
##  parameter 'adjust' was held constant at a value of 1
## Accuracy was used to select the optimal model using the largest value.
## The final values used for the model were fL = 0, usekernel = FALSE and adjust
##  = 1.

Train data from training set

model <- NaiveBayes(Outcome~., data=data_train)
model
## $apriori
## grouping
##         0         1 
## 0.6505576 0.3494424 
## 
## $tables
## $tables$Pregnancies
##       [,1]     [,2]
## 0 3.234286 2.955636
## 1 4.755319 3.720693
## 
## $tables$Glucose
##       [,1]     [,2]
## 0 110.9314 26.65724
## 1 140.7660 33.68902
## 
## $tables$BloodPressure
##       [,1]     [,2]
## 0 68.45429 17.69260
## 1 72.38298 20.00754
## 
## $tables$SkinThickness
##       [,1]     [,2]
## 0 19.40571 14.90739
## 1 22.72340 16.68738
## 
## $tables$Insulin
##        [,1]     [,2]
## 0  74.33429 106.4203
## 1 104.64894 144.9853
## 
## $tables$BMI
##       [,1]     [,2]
## 0 30.50429 7.567152
## 1 35.48298 6.668517
## 
## $tables$DiabetesPedigreeFunction
##        [,1]      [,2]
## 0 0.4280171 0.3016743
## 1 0.5776915 0.4038558
## 
## $tables$Age
##       [,1]     [,2]
## 0 30.81429 11.49099
## 1 36.93617 10.61964
## 
## 
## $levels
## [1] "0" "1"
## 
## $call
## NaiveBayes.default(x = X, grouping = Y)
## 
## $x
##     Pregnancies Glucose BloodPressure SkinThickness Insulin  BMI
## 1             6     148            72            35       0 33.6
## 2             1      85            66            29       0 26.6
## 3             8     183            64             0       0 23.3
## 4             1      89            66            23      94 28.1
## 5             0     137            40            35     168 43.1
## 6             5     116            74             0       0 25.6
## 7             3      78            50            32      88 31.0
## 8            10     115             0             0       0 35.3
## 9             2     197            70            45     543 30.5
## 10            4     110            92             0       0 37.6
## 11           10     168            74             0       0 38.0
## 12           10     139            80             0       0 27.1
## 13            1     189            60            23     846 30.1
## 14            5     166            72            19     175 25.8
## 15            7     100             0             0       0 30.0
## 16            0     118            84            47     230 45.8
## 17            1     103            30            38      83 43.3
## 18            1     115            70            30      96 34.6
## 19            3     126            88            41     235 39.3
## 20            8      99            84             0       0 35.4
## 21            7     196            90             0       0 39.8
## 22            9     119            80            35       0 29.0
## 23           10     125            70            26     115 31.1
## 24            7     147            76             0       0 39.4
## 25           13     145            82            19     110 22.2
## 26            5     117            92             0       0 34.1
## 27            5     109            75            26       0 36.0
## 28            3      88            58            11      54 24.8
## 29            6      92            92             0       0 19.9
## 30           10     122            78            31       0 27.6
## 31            4     103            60            33     192 24.0
## 32           11     138            76             0       0 33.2
## 33            9     102            76            37       0 32.9
## 34            2      90            68            42       0 38.2
## 35            4     111            72            47     207 37.1
## 36            3     180            64            25      70 34.0
## 37            7     106            92            18       0 22.7
## 38            7     159            64             0       0 27.4
## 39            0     180            66            39       0 42.0
## 40            1     146            56             0       0 29.7
## 41            7     103            66            32       0 39.1
## 42            7     150            66            42     342 34.7
## 43            1      73            50            10       0 23.0
## 44            0     100            88            60     110 46.8
## 45            0     146            82             0       0 40.5
## 46            0     105            64            41     142 41.5
## 47            2      84             0             0       0  0.0
## 48            8     133            72             0       0 32.9
## 49            5      44            62             0       0 25.0
## 50            0     109            88            30       0 32.5
## 51            2     109            92             0       0 42.7
## 52           13     126            90             0       0 43.4
## 53            4     129            86            20     270 35.1
## 54            1      79            75            30       0 32.0
## 55            1       0            48            20       0 24.7
## 56            7      62            78             0       0 32.6
## 57            0     131             0             0       0 43.2
## 58            2     112            66            22       0 25.0
## 59            3     113            44            13       0 22.4
## 60            2      74             0             0       0  0.0
## 61            7      83            78            26      71 29.3
## 62            0     101            65            28       0 24.6
## 63            2     110            74            29     125 32.4
## 64           13     106            72            54       0 36.6
## 65           15     136            70            32     110 37.1
## 66            1     107            68            19       0 26.5
## 67            1      80            55             0       0 19.1
## 68            4     123            80            15     176 32.0
## 69            2     142            82            18      64 24.7
## 70            6     144            72            27     228 33.9
## 71            2      92            62            28       0 31.6
## 72            6      93            50            30      64 28.7
## 73            1     163            72             0       0 39.0
## 74            1     151            60             0       0 26.1
## 75            0     125            96             0       0 22.5
## 76            1      96           122             0       0 22.4
## 77            4     144            58            28     140 29.5
## 78            3      83            58            31      18 34.3
## 79            0      95            85            25      36 37.4
## 80            3     171            72            33     135 33.3
## 81            8     155            62            26     495 34.0
## 82            7     160            54            32     175 30.5
## 83            4     146            92             0       0 31.2
## 84            5     124            74             0       0 34.0
## 85            5      78            48             0       0 33.7
## 86            4      99            76            15      51 23.2
## 87            6     111            64            39       0 34.2
## 88            2     107            74            30     100 33.6
## 89            5     132            80             0       0 26.8
## 90            0     113            76             0       0 33.3
## 91            3     120            70            30     135 42.9
## 92            1     118            58            36      94 33.3
## 93            1     117            88            24     145 34.5
## 94            4     173            70            14     168 29.7
## 95            9     122            56             0       0 33.3
## 96            3     170            64            37     225 34.5
## 97            8      84            74            31       0 38.3
## 98            2      96            68            13      49 21.1
## 99            0     100            70            26      50 30.8
## 100           0      93            60            25      92 28.7
## 101           0     129            80             0       0 31.2
## 102           5     105            72            29     325 36.9
## 103           3     128            78             0       0 21.1
## 104           5     106            82            30       0 39.5
## 105           2     108            52            26      63 32.5
## 106           4     154            62            31     284 32.8
## 107           0     102            75            23       0  0.0
## 108           5     147            78             0       0 33.7
## 109           2      90            70            17       0 27.3
## 110           1     136            74            50     204 37.4
## 111           4     114            65             0       0 21.9
## 112           9     156            86            28     155 34.3
## 113           1     153            82            42     485 40.6
## 114           7     152            88            44       0 50.0
## 115           2      99            52            15      94 24.6
## 116           1     109            56            21     135 25.2
## 117           2      88            74            19      53 29.0
## 118           7     102            74            40     105 37.2
## 119           0     114            80            34     285 44.2
## 120           0     131            88             0       0 31.6
## 121           6     104            74            18     156 29.9
## 122           4     120            68             0       0 29.6
## 123           4     110            66             0       0 31.9
## 124           3     111            90            12      78 28.4
## 125           6     134            70            23     130 35.4
## 126           2      87             0            23       0 28.9
## 127           1      79            60            42      48 43.5
## 128           6      85            78             0       0 31.2
## 129           0     129           110            46     130 67.1
## 130           5     130            82             0       0 39.1
## 131           1       0            74            20      23 27.7
## 132           4     141            74             0       0 27.6
## 133           7     194            68            28       0 35.9
## 134           8     181            68            36     495 30.1
## 135           1     128            98            41      58 32.0
## 136           5     139            80            35     160 31.6
## 137           3     111            62             0       0 22.6
## 138           9     123            70            44      94 33.1
## 139           7     159            66             0       0 30.4
## 140          11     135             0             0       0 52.3
## 141           8      85            55            20       0 24.4
## 142           5     158            84            41     210 39.4
## 143           1     105            58             0       0 24.3
## 144           3     107            62            13      48 22.9
## 145           4     148            60            27     318 30.9
## 146           0     113            80            16       0 31.0
## 147           5     111            72            28       0 23.9
## 148           8     196            76            29     280 37.5
## 149           5     162           104             0       0 37.7
## 150           1      96            64            27      87 33.2
## 151           7     184            84            33       0 35.5
## 152           2      81            60            22       0 27.7
## 153           0     147            85            54       0 42.8
## 154           7     179            95            31       0 34.2
## 155           0     140            65            26     130 42.6
## 156           9     112            82            32     175 34.2
## 157           5     109            62            41     129 35.8
## 158           6     125            68            30     120 30.0
## 159           5      85            74            22       0 29.0
## 160           2     158            90             0       0 31.6
## 161           7     119             0             0       0 25.2
## 162           1     100            66            15      56 23.6
## 163           1      87            78            27      32 34.6
## 164           0     101            76             0       0 35.7
## 165           4     197            70            39     744 36.7
## 166           0     117            80            31      53 45.2
## 167           6     134            80            37     370 46.2
## 168           1      79            80            25      37 25.4
## 169           3      74            68            28      45 29.7
## 170           7     181            84            21     192 35.9
## 171           9     164            84            21       0 30.8
## 172           1      91            64            24       0 29.2
## 173           4      91            70            32      88 33.1
## 174           3     139            54             0       0 25.6
## 175           6     119            50            22     176 27.1
## 176           9     184            85            15       0 30.0
## 177           0     165            90            33     680 52.3
## 178           9     124            70            33     402 35.4
## 179           2      90            80            14      55 24.4
## 180          12      92            62             7     258 27.6
## 181           3     111            56            39       0 30.1
## 182           2     114            68            22       0 28.7
## 183          11     155            76            28     150 33.3
## 184           3     191            68            15     130 30.9
## 185           3     141             0             0       0 30.0
## 186           4      95            70            32       0 32.1
## 187           4     123            62             0       0 32.0
## 188           0     138             0             0       0 36.3
## 189           2     128            64            42       0 40.0
## 190           0     102            52             0       0 25.1
## 191          10     101            86            37       0 45.6
## 192           3     122            78             0       0 23.0
## 193           1      71            78            50      45 33.2
## 194           7     106            60            24       0 26.5
## 195           2     108            62            10     278 25.3
## 196           0     146            70             0       0 37.9
## 197          10     129            76            28     122 35.9
## 198           7     133            88            15     155 32.4
## 199           2     108            80             0       0 27.0
## 200           7     136            74            26     135 26.0
## 201           5     155            84            44     545 38.7
## 202           1     119            86            39     220 45.6
## 203           0      78            88            29      40 36.9
## 204           0     107            62            30      74 36.6
## 205           2     128            78            37     182 43.3
## 206           0     161            50             0       0 21.9
## 207           6     151            62            31     120 35.5
## 208          14     100            78            25     184 36.6
## 209           8     112            72             0       0 23.6
## 210           2     144            58            33     135 31.6
## 211           5      77            82            41      42 35.8
## 212           5     115            98             0       0 52.9
## 213           3     150            76             0       0 21.0
## 214           2     120            76            37     105 39.7
## 215          10     161            68            23     132 25.5
## 216           0     137            68            14     148 24.8
## 217           2     155            74            17      96 26.6
## 218           3     113            50            10      85 29.5
## 219           7     109            80            31       0 35.9
## 220           3      99            80            11      64 19.3
## 221           3     182            74             0       0 30.5
## 222           6     194            78             0       0 23.5
## 223           4     129            60            12     231 27.5
## 224           3     112            74            30       0 31.6
## 225           0     124            70            20       0 27.4
## 226          13     152            90            33      29 26.8
## 227           2     112            75            32       0 35.7
## 228           1     157            72            21     168 25.6
## 229           1     122            64            32     156 35.1
## 230          10     179            70             0       0 35.1
## 231           2     102            86            36     120 45.5
## 232           6     105            70            32      68 30.8
## 233           8     118            72            19       0 23.1
## 234           2      87            58            16      52 32.7
## 235           1     180             0             0       0 43.3
## 236           1      95            60            18      58 23.9
## 237           0     165            76            43     255 47.9
## 238           0     117             0             0       0 33.8
## 239           5     115            76             0       0 31.2
## 240           9     152            78            34     171 34.2
## 241           7     178            84             0       0 39.9
## 242           1     130            70            13     105 25.9
## 243           1      95            74            21      73 25.9
## 244           1     139            46            19      83 28.7
## 245           3      99            62            19      74 21.8
## 246           5       0            80            32       0 41.0
## 247           4      92            80             0       0 42.2
## 248           4     137            84             0       0 31.2
## 249           3      61            82            28       0 34.4
## 250           1      90            62            12      43 27.2
## 251           3      90            78             0       0 42.7
## 252           1     125            50            40     167 33.3
## 253          12      88            74            40      54 35.3
## 254           1     196            76            36     249 36.5
## 255           5     189            64            33     325 31.2
## 256           5     103           108            37       0 39.2
## 257           4     147            74            25     293 34.9
## 258           6     124            72             0       0 27.6
## 259           0     101            64            17       0 21.0
## 260           3      81            86            16      66 27.5
## 261           1     133           102            28     140 32.8
## 262           3     173            82            48     465 38.4
## 263           0      84            64            22      66 35.8
## 264           2     105            58            40      94 34.9
## 265           2     122            52            43     158 36.2
## 266          12     140            82            43     325 39.2
## 267           0      98            82            15      84 25.2
## 268           1      87            60            37      75 37.2
## 269           0      93           100            39      72 43.4
## 270           1     107            72            30      82 30.8
## 271           0     105            68            22       0 20.0
## 272           1     109            60             8     182 25.4
## 273           1      90            62            18      59 25.1
## 274           1     119            54            13      50 22.3
## 275           5     116            74            29       0 32.3
## 276           8     105           100            36       0 43.3
## 277           5     144            82            26     285 32.0
## 278           5     166            76             0       0 45.7
## 279           4     116            72            12      87 22.1
## 280           4     158            78             0       0 32.9
## 281           2     127            58            24     275 27.7
## 282           3      96            56            34     115 24.7
## 283           0     131            66            40       0 34.3
## 284           3      82            70             0       0 21.1
## 285           3     193            70            31       0 34.9
## 286           4      95            64             0       0 32.0
## 287           5     136            84            41      88 35.0
## 288           9      72            78            25       0 31.6
## 289           2     123            48            32     165 42.1
## 290           8     197            74             0       0 25.9
## 291           1     172            68            49     579 42.4
## 292           1     112            72            30     176 34.4
## 293           1     143            84            23     310 42.4
## 294           3     173            84            33     474 35.7
## 295           1      97            68            21       0 27.2
## 296           4     144            82            32       0 38.5
## 297           3     129            64            29     115 26.4
## 298           1     119            88            41     170 45.3
## 299           2      94            68            18      76 26.0
## 300           0     102            64            46      78 40.6
## 301           8     151            78            32     210 42.9
## 302           4     184            78            39     277 37.0
## 303           1     181            64            30     180 34.1
## 304           0     135            94            46     145 40.6
## 305           1      95            82            25     180 35.0
## 306           2      99             0             0       0 22.2
## 307           3      89            74            16      85 30.4
## 308           1      80            74            11      60 30.0
## 309           2     139            75             0       0 25.6
## 310           5     147            75             0       0 29.9
## 311           6     107            88             0       0 36.8
## 312           0     189           104            25       0 34.3
## 313           4     117            64            27     120 33.2
## 314           8     108            70             0       0 30.5
## 315           4     117            62            12       0 29.7
## 316           0     180            78            63      14 59.4
## 317           0     120            74            18      63 30.5
## 318           1      82            64            13      95 21.2
## 319           2     134            70             0       0 28.9
## 320           0      91            68            32     210 39.9
## 321           2     100            54            28     105 37.8
## 322           1     135            54             0       0 26.7
## 323           1      71            62             0       0 21.8
## 324           8      74            70            40      49 35.3
## 325           5      88            78            30       0 27.6
## 326           0     124            56            13     105 21.8
## 327           0      97            64            36     100 36.8
## 328           8     120             0             0       0 30.0
## 329           6     154            78            41     140 46.1
## 330           0     137            70            38       0 33.2
## 331           0     119            66            27       0 38.8
## 332           7     136            90             0       0 29.9
## 333           4     114            64             0       0 28.9
## 334           0     137            84            27       0 27.3
## 335           4     132            86            31       0 28.0
## 336           3     158            70            30     328 35.5
## 337           0     123            88            37       0 35.2
## 338           4      85            58            22      49 27.8
## 339           0      84            82            31     125 38.2
## 340           0     145             0             0       0 44.2
## 341           0     135            68            42     250 42.3
## 342           1     139            62            41     480 40.7
## 343           0     173            78            32     265 46.5
## 344           4      99            72            17       0 25.6
## 345           8     194            80             0       0 26.1
## 346           2      83            65            28      66 36.8
## 347           4      99            68            38       0 32.8
## 348           4     125            70            18     122 28.9
## 349           3      80             0             0       0  0.0
## 350           6     166            74             0       0 26.6
## 351           5     110            68             0       0 26.0
## 352           2      81            72            15      76 30.1
## 353           7     195            70            33     145 25.1
## 354           6     154            74            32     193 29.3
## 355           2     117            90            19      71 25.2
## 356           3      84            72            32       0 37.2
## 357           6       0            68            41       0 39.0
## 358           7      94            64            25      79 33.3
## 359           2      84            50            23      76 30.4
## 360           8     120            78             0       0 25.0
## 361          12      84            72            31       0 29.7
## 362           0     139            62            17     210 22.1
## 363           9      91            68             0       0 24.2
## 364           7     125            86             0       0 37.6
## 365          13      76            60             0       0 32.8
## 366           6     129            90             7     326 19.6
## 367           3     124            80            33     130 33.2
## 368           6     114             0             0       0  0.0
## 369           9     130            70             0       0 34.2
## 370           3     125            58             0       0 31.6
## 371           3      87            60            18       0 21.8
## 372           1      97            64            19      82 18.2
## 373           3     116            74            15     105 26.3
## 374           0     117            66            31     188 30.8
## 375           0     111            65             0       0 24.6
## 376           2     122            60            18     106 29.8
## 377           0     107            76             0       0 45.3
## 378           1      77            56            30      56 33.3
## 379           0      57            60             0       0 21.7
## 380           0     127            80            37     210 36.3
## 381           3     129            92            49     155 36.4
## 382          10      90            85            32       0 34.9
## 383           4      84            90            23      56 39.5
## 384           1      88            78            29      76 32.0
## 385           5     187            76            27     207 43.6
## 386           4     131            68            21     166 33.1
## 387           1     164            82            43      67 32.8
## 388           1      88            62            24      44 29.9
## 389           1      84            64            23     115 36.9
## 390           7     124            70            33     215 25.5
## 391          11      85            74             0       0 30.1
## 392           6     125            76             0       0 33.8
## 393           0     198            66            32     274 41.3
## 394           6      99            60            19      54 26.9
## 395           2      95            54            14      88 26.1
## 396           6      92            62            32     126 32.0
## 397           4     154            72            29     126 31.3
## 398           0     121            66            30     165 34.3
## 399           2     130            96             0       0 22.6
## 400           3     111            58            31      44 29.5
## 401           2      98            60            17     120 34.7
## 402           6     108            44            20     130 24.0
## 403           2     118            80             0       0 42.9
## 404          10     133            68             0       0 27.0
## 405           0     151            90            46       0 42.1
## 406           6     109            60            27       0 25.0
## 407          12     121            78            17       0 26.5
## 408           8     100            76             0       0 38.7
## 409           8     124            76            24     600 28.7
## 410           1      93            56            11       0 22.5
## 411           6     103            66             0       0 24.3
## 412           3     176            86            27     156 33.3
## 413           0      73             0             0       0 21.1
## 414          11     111            84            40       0 46.8
## 415           2     112            78            50     140 39.4
## 416           6     123            72            45     230 33.6
## 417           0     188            82            14     185 32.0
## 418           0      67            76             0       0 45.3
## 419           1     173            74             0       0 36.8
## 420           1     109            38            18     120 23.1
## 421           1     108            88            19       0 27.1
## 422           6      96             0             0       0 23.7
## 423           7     150            78            29     126 35.2
## 424           1     124            60            32       0 35.8
## 425           1     181            78            42     293 40.0
## 426           1      92            62            25      41 19.5
## 427           0     152            82            39     272 41.5
## 428           3     106            54            21     158 30.9
## 429           7     168            88            42     321 38.2
## 430          11     138            74            26     144 36.1
## 431           3     106            72             0       0 25.8
## 432           6     117            96             0       0 28.7
## 433           2      68            62            13      15 20.1
## 434           9     112            82            24       0 28.2
## 435           0     119             0             0       0 32.4
## 436           2     112            86            42     160 38.4
## 437           2      92            76            20       0 24.2
## 438           6     183            94             0       0 40.8
## 439           2     108            64             0       0 30.8
## 440           4      90            88            47      54 37.7
## 441           0     125            68             0       0 24.7
## 442           0     132            78             0       0 32.4
## 443           5     128            80             0       0 34.6
## 444           2     111            60             0       0 26.2
## 445           1     128            82            17     183 27.5
## 446          10      92            62             0       0 25.9
## 447          13     104            72             0       0 31.2
## 448           5     104            74             0       0 28.8
## 449           2      94            76            18      66 31.6
## 450           0     102            86            17     105 29.3
## 451           6     147            80             0       0 29.5
## 452           3     103            72            30     152 27.6
## 453           2     157            74            35     440 39.4
## 454           1     167            74            17     144 23.4
## 455           0     179            50            36     159 37.8
## 456          11     136            84            35     130 28.3
## 457           5     123            74            40      77 34.1
## 458           2     120            54             0       0 26.8
## 459           1     106            70            28     135 34.2
## 460           2     101            58            35      90 21.8
## 461           1     120            80            48     200 38.9
## 462          11     127           106             0       0 39.0
## 463           3      80            82            31      70 34.2
## 464          10     162            84             0       0 27.7
## 465           1     199            76            43       0 42.9
## 466           8     167           106            46     231 37.6
## 467           6     115            60            39       0 33.7
## 468           6     165            68            26     168 33.6
## 469           1      99            58            10       0 25.4
## 470           3     123           100            35     240 57.3
## 471           8      91            82             0       0 35.6
## 472           6     195            70             0       0 30.9
## 473           9     156            86             0       0 24.8
## 474           0      93            60             0       0 35.3
## 475           3     121            52             0       0 36.0
## 476           2     101            58            17     265 24.2
## 477           2      56            56            28      45 24.2
## 478           0     162            76            36       0 49.6
## 479           0      95            64            39     105 44.6
## 480           4     125            80             0       0 32.3
## 481           3     130            64             0       0 23.1
## 482           1     107            50            19       0 28.3
## 483           1     140            74            26     180 24.1
## 484           1     144            82            46     180 46.1
## 485          13     158           114             0       0 42.3
## 486           2     121            70            32      95 39.1
## 487           7     129            68            49     125 38.5
## 488           7     142            90            24     480 30.4
## 489           0      99             0             0       0 25.0
## 490           4     127            88            11     155 34.5
## 491           4     118            70             0       0 44.5
## 492           2     122            76            27     200 35.9
## 493           6     125            78            31       0 27.6
## 494           1     168            88            29       0 35.0
## 495           4     110            76            20     100 28.4
## 496           2     127            46            21     335 34.4
## 497           2      93            64            32     160 38.0
## 498           3     158            64            13     387 31.2
## 499           5     126            78            27      22 29.6
## 500          10     129            62            36       0 41.2
## 501           3     102            74             0       0 29.5
## 502           3     173            78            39     185 33.8
## 503          10      94            72            18       0 23.1
## 504           1     108            60            46     178 35.5
## 505           4      83            86            19       0 29.3
## 506           1     114            66            36     200 38.1
## 507           5     117            86            30     105 39.1
## 508           1     116            78            29     180 36.1
## 509           0     141            84            26       0 32.4
## 510           2     175            88             0       0 22.9
## 511           2      92            52             0       0 30.1
## 512           2     174            88            37     120 44.5
## 513           2     105            75             0       0 23.3
## 514           4      95            60            32       0 35.4
## 515           0     126            86            27     120 27.4
## 516           8      65            72            23       0 32.0
## 517           2      99            60            17     160 36.6
## 518           1     102            74             0       0 39.5
## 519          11     120            80            37     150 42.3
## 520           3     102            44            20      94 30.8
## 521           1     109            58            18     116 28.5
## 522           9     140            94             0       0 32.7
## 523          12     100            84            33     105 30.0
## 524           1     147            94            41       0 49.3
## 525           3     187            70            22     200 36.4
## 526           1     121            78            39      74 39.0
## 527           3     108            62            24       0 26.0
## 528           0     181            88            44     510 43.3
## 529           1     128            88            39     110 36.5
## 530           0     123            72             0       0 36.3
## 531           1     106            76             0       0 37.5
## 532           6     190            92             0       0 35.5
## 533           2      88            58            26      16 28.4
## 534           9      89            62             0       0 22.5
## 535          10     101            76            48     180 32.9
## 536           2     122            70            27       0 36.8
## 537           5     121            72            23     112 26.2
## 538           1      93            70            31       0 30.4
##     DiabetesPedigreeFunction Age
## 1                      0.627  50
## 2                      0.351  31
## 3                      0.672  32
## 4                      0.167  21
## 5                      2.288  33
## 6                      0.201  30
## 7                      0.248  26
## 8                      0.134  29
## 9                      0.158  53
## 10                     0.191  30
## 11                     0.537  34
## 12                     1.441  57
## 13                     0.398  59
## 14                     0.587  51
## 15                     0.484  32
## 16                     0.551  31
## 17                     0.183  33
## 18                     0.529  32
## 19                     0.704  27
## 20                     0.388  50
## 21                     0.451  41
## 22                     0.263  29
## 23                     0.205  41
## 24                     0.257  43
## 25                     0.245  57
## 26                     0.337  38
## 27                     0.546  60
## 28                     0.267  22
## 29                     0.188  28
## 30                     0.512  45
## 31                     0.966  33
## 32                     0.420  35
## 33                     0.665  46
## 34                     0.503  27
## 35                     1.390  56
## 36                     0.271  26
## 37                     0.235  48
## 38                     0.294  40
## 39                     1.893  25
## 40                     0.564  29
## 41                     0.344  31
## 42                     0.718  42
## 43                     0.248  21
## 44                     0.962  31
## 45                     1.781  44
## 46                     0.173  22
## 47                     0.304  21
## 48                     0.270  39
## 49                     0.587  36
## 50                     0.855  38
## 51                     0.845  54
## 52                     0.583  42
## 53                     0.231  23
## 54                     0.396  22
## 55                     0.140  22
## 56                     0.391  41
## 57                     0.270  26
## 58                     0.307  24
## 59                     0.140  22
## 60                     0.102  22
## 61                     0.767  36
## 62                     0.237  22
## 63                     0.698  27
## 64                     0.178  45
## 65                     0.153  43
## 66                     0.165  24
## 67                     0.258  21
## 68                     0.443  34
## 69                     0.761  21
## 70                     0.255  40
## 71                     0.130  24
## 72                     0.356  23
## 73                     1.222  33
## 74                     0.179  22
## 75                     0.262  21
## 76                     0.207  27
## 77                     0.287  37
## 78                     0.336  25
## 79                     0.247  24
## 80                     0.199  24
## 81                     0.543  46
## 82                     0.588  39
## 83                     0.539  61
## 84                     0.220  38
## 85                     0.654  25
## 86                     0.223  21
## 87                     0.260  24
## 88                     0.404  23
## 89                     0.186  69
## 90                     0.278  23
## 91                     0.452  30
## 92                     0.261  23
## 93                     0.403  40
## 94                     0.361  33
## 95                     1.114  33
## 96                     0.356  30
## 97                     0.457  39
## 98                     0.647  26
## 99                     0.597  21
## 100                    0.532  22
## 101                    0.703  29
## 102                    0.159  28
## 103                    0.268  55
## 104                    0.286  38
## 105                    0.318  22
## 106                    0.237  23
## 107                    0.572  21
## 108                    0.218  65
## 109                    0.085  22
## 110                    0.399  24
## 111                    0.432  37
## 112                    1.189  42
## 113                    0.687  23
## 114                    0.337  36
## 115                    0.637  21
## 116                    0.833  23
## 117                    0.229  22
## 118                    0.204  45
## 119                    0.167  27
## 120                    0.743  32
## 121                    0.722  41
## 122                    0.709  34
## 123                    0.471  29
## 124                    0.495  29
## 125                    0.542  29
## 126                    0.773  25
## 127                    0.678  23
## 128                    0.382  42
## 129                    0.319  26
## 130                    0.956  37
## 131                    0.299  21
## 132                    0.244  40
## 133                    0.745  41
## 134                    0.615  60
## 135                    1.321  33
## 136                    0.361  25
## 137                    0.142  21
## 138                    0.374  40
## 139                    0.383  36
## 140                    0.578  40
## 141                    0.136  42
## 142                    0.395  29
## 143                    0.187  21
## 144                    0.678  23
## 145                    0.150  29
## 146                    0.874  21
## 147                    0.407  27
## 148                    0.605  57
## 149                    0.151  52
## 150                    0.289  21
## 151                    0.355  41
## 152                    0.290  25
## 153                    0.375  24
## 154                    0.164  60
## 155                    0.431  24
## 156                    0.260  36
## 157                    0.514  25
## 158                    0.464  32
## 159                    1.224  32
## 160                    0.805  66
## 161                    0.209  37
## 162                    0.666  26
## 163                    0.101  22
## 164                    0.198  26
## 165                    2.329  31
## 166                    0.089  24
## 167                    0.238  46
## 168                    0.583  22
## 169                    0.293  23
## 170                    0.586  51
## 171                    0.831  32
## 172                    0.192  21
## 173                    0.446  22
## 174                    0.402  22
## 175                    1.318  33
## 176                    1.213  49
## 177                    0.427  23
## 178                    0.282  34
## 179                    0.249  24
## 180                    0.926  44
## 181                    0.557  30
## 182                    0.092  25
## 183                    1.353  51
## 184                    0.299  34
## 185                    0.761  27
## 186                    0.612  24
## 187                    0.226  35
## 188                    0.933  25
## 189                    1.101  24
## 190                    0.078  21
## 191                    1.136  38
## 192                    0.254  40
## 193                    0.422  21
## 194                    0.296  29
## 195                    0.881  22
## 196                    0.334  28
## 197                    0.280  39
## 198                    0.262  37
## 199                    0.259  52
## 200                    0.647  51
## 201                    0.619  34
## 202                    0.808  29
## 203                    0.434  21
## 204                    0.757  25
## 205                    1.224  31
## 206                    0.254  65
## 207                    0.692  28
## 208                    0.412  46
## 209                    0.840  58
## 210                    0.422  25
## 211                    0.156  35
## 212                    0.209  28
## 213                    0.207  37
## 214                    0.215  29
## 215                    0.326  47
## 216                    0.143  21
## 217                    0.433  27
## 218                    0.626  25
## 219                    1.127  43
## 220                    0.284  30
## 221                    0.345  29
## 222                    0.129  59
## 223                    0.527  31
## 224                    0.197  25
## 225                    0.254  36
## 226                    0.731  43
## 227                    0.148  21
## 228                    0.123  24
## 229                    0.692  30
## 230                    0.200  37
## 231                    0.127  23
## 232                    0.122  37
## 233                    1.476  46
## 234                    0.166  25
## 235                    0.282  41
## 236                    0.260  22
## 237                    0.259  26
## 238                    0.932  44
## 239                    0.343  44
## 240                    0.893  33
## 241                    0.331  41
## 242                    0.472  22
## 243                    0.673  36
## 244                    0.654  22
## 245                    0.279  26
## 246                    0.346  37
## 247                    0.237  29
## 248                    0.252  30
## 249                    0.243  46
## 250                    0.580  24
## 251                    0.559  21
## 252                    0.962  28
## 253                    0.378  48
## 254                    0.875  29
## 255                    0.583  29
## 256                    0.305  65
## 257                    0.385  30
## 258                    0.368  29
## 259                    0.252  21
## 260                    0.306  22
## 261                    0.234  45
## 262                    2.137  25
## 263                    0.545  21
## 264                    0.225  25
## 265                    0.816  28
## 266                    0.528  58
## 267                    0.299  22
## 268                    0.509  22
## 269                    1.021  35
## 270                    0.821  24
## 271                    0.236  22
## 272                    0.947  21
## 273                    1.268  25
## 274                    0.205  24
## 275                    0.660  35
## 276                    0.239  45
## 277                    0.452  58
## 278                    0.340  27
## 279                    0.463  37
## 280                    0.803  31
## 281                    1.600  25
## 282                    0.944  39
## 283                    0.196  22
## 284                    0.389  25
## 285                    0.241  25
## 286                    0.161  31
## 287                    0.286  35
## 288                    0.280  38
## 289                    0.520  26
## 290                    1.191  39
## 291                    0.702  28
## 292                    0.528  25
## 293                    1.076  22
## 294                    0.258  22
## 295                    1.095  22
## 296                    0.554  37
## 297                    0.219  28
## 298                    0.507  26
## 299                    0.561  21
## 300                    0.496  21
## 301                    0.516  36
## 302                    0.264  31
## 303                    0.328  38
## 304                    0.284  26
## 305                    0.233  43
## 306                    0.108  23
## 307                    0.551  38
## 308                    0.527  22
## 309                    0.167  29
## 310                    0.434  28
## 311                    0.727  31
## 312                    0.435  41
## 313                    0.230  24
## 314                    0.955  33
## 315                    0.380  30
## 316                    2.420  25
## 317                    0.285  26
## 318                    0.415  23
## 319                    0.542  23
## 320                    0.381  25
## 321                    0.498  24
## 322                    0.687  62
## 323                    0.416  26
## 324                    0.705  39
## 325                    0.258  37
## 326                    0.452  21
## 327                    0.600  25
## 328                    0.183  38
## 329                    0.571  27
## 330                    0.170  22
## 331                    0.259  22
## 332                    0.210  50
## 333                    0.126  24
## 334                    0.231  59
## 335                    0.419  63
## 336                    0.344  35
## 337                    0.197  29
## 338                    0.306  28
## 339                    0.233  23
## 340                    0.630  31
## 341                    0.365  24
## 342                    0.536  21
## 343                    1.159  58
## 344                    0.294  28
## 345                    0.551  67
## 346                    0.629  24
## 347                    0.145  33
## 348                    1.144  45
## 349                    0.174  22
## 350                    0.304  66
## 351                    0.292  30
## 352                    0.547  25
## 353                    0.163  55
## 354                    0.839  39
## 355                    0.313  21
## 356                    0.267  28
## 357                    0.727  41
## 358                    0.738  41
## 359                    0.968  21
## 360                    0.409  64
## 361                    0.297  46
## 362                    0.207  21
## 363                    0.200  58
## 364                    0.304  51
## 365                    0.180  41
## 366                    0.582  60
## 367                    0.305  26
## 368                    0.189  26
## 369                    0.652  45
## 370                    0.151  24
## 371                    0.444  21
## 372                    0.299  21
## 373                    0.107  24
## 374                    0.493  22
## 375                    0.660  31
## 376                    0.717  22
## 377                    0.686  24
## 378                    1.251  24
## 379                    0.735  67
## 380                    0.804  23
## 381                    0.968  32
## 382                    0.825  56
## 383                    0.159  25
## 384                    0.365  29
## 385                    1.034  53
## 386                    0.160  28
## 387                    0.341  50
## 388                    0.422  23
## 389                    0.471  28
## 390                    0.161  37
## 391                    0.300  35
## 392                    0.121  54
## 393                    0.502  28
## 394                    0.497  32
## 395                    0.748  22
## 396                    0.085  46
## 397                    0.338  37
## 398                    0.203  33
## 399                    0.268  21
## 400                    0.430  22
## 401                    0.198  22
## 402                    0.813  35
## 403                    0.693  21
## 404                    0.245  36
## 405                    0.371  21
## 406                    0.206  27
## 407                    0.259  62
## 408                    0.190  42
## 409                    0.687  52
## 410                    0.417  22
## 411                    0.249  29
## 412                    1.154  52
## 413                    0.342  25
## 414                    0.925  45
## 415                    0.175  24
## 416                    0.733  34
## 417                    0.682  22
## 418                    0.194  46
## 419                    0.088  38
## 420                    0.407  26
## 421                    0.400  24
## 422                    0.190  28
## 423                    0.692  54
## 424                    0.514  21
## 425                    1.258  22
## 426                    0.482  25
## 427                    0.270  27
## 428                    0.292  24
## 429                    0.787  40
## 430                    0.557  50
## 431                    0.207  27
## 432                    0.157  30
## 433                    0.257  23
## 434                    1.282  50
## 435                    0.141  24
## 436                    0.246  28
## 437                    1.698  28
## 438                    1.461  45
## 439                    0.158  21
## 440                    0.362  29
## 441                    0.206  21
## 442                    0.393  21
## 443                    0.144  45
## 444                    0.343  23
## 445                    0.115  22
## 446                    0.167  31
## 447                    0.465  38
## 448                    0.153  48
## 449                    0.649  23
## 450                    0.695  27
## 451                    0.178  50
## 452                    0.730  27
## 453                    0.134  30
## 454                    0.447  33
## 455                    0.455  22
## 456                    0.260  42
## 457                    0.269  28
## 458                    0.455  27
## 459                    0.142  22
## 460                    0.155  22
## 461                    1.162  41
## 462                    0.190  51
## 463                    1.292  27
## 464                    0.182  54
## 465                    1.394  22
## 466                    0.165  43
## 467                    0.245  40
## 468                    0.631  49
## 469                    0.551  21
## 470                    0.880  22
## 471                    0.587  68
## 472                    0.328  31
## 473                    0.230  53
## 474                    0.263  25
## 475                    0.127  25
## 476                    0.614  23
## 477                    0.332  22
## 478                    0.364  26
## 479                    0.366  22
## 480                    0.536  27
## 481                    0.314  22
## 482                    0.181  29
## 483                    0.828  23
## 484                    0.335  46
## 485                    0.257  44
## 486                    0.886  23
## 487                    0.439  43
## 488                    0.128  43
## 489                    0.253  22
## 490                    0.598  28
## 491                    0.904  26
## 492                    0.483  26
## 493                    0.565  49
## 494                    0.905  52
## 495                    0.118  27
## 496                    0.176  22
## 497                    0.674  23
## 498                    0.295  24
## 499                    0.439  40
## 500                    0.441  38
## 501                    0.121  32
## 502                    0.970  31
## 503                    0.595  56
## 504                    0.415  24
## 505                    0.317  34
## 506                    0.289  21
## 507                    0.251  42
## 508                    0.496  25
## 509                    0.433  22
## 510                    0.326  22
## 511                    0.141  22
## 512                    0.646  24
## 513                    0.560  53
## 514                    0.284  28
## 515                    0.515  21
## 516                    0.600  42
## 517                    0.453  21
## 518                    0.293  42
## 519                    0.785  48
## 520                    0.400  26
## 521                    0.219  22
## 522                    0.734  45
## 523                    0.488  46
## 524                    0.358  27
## 525                    0.408  36
## 526                    0.261  28
## 527                    0.223  25
## 528                    0.222  26
## 529                    1.057  37
## 530                    0.258  52
## 531                    0.197  26
## 532                    0.278  66
## 533                    0.766  22
## 534                    0.142  33
## 535                    0.171  63
## 536                    0.340  27
## 537                    0.245  30
## 538                    0.315  23
## 
## $usekernel
## [1] FALSE
## 
## $varnames
## [1] "Pregnancies"              "Glucose"                 
## [3] "BloodPressure"            "SkinThickness"           
## [5] "Insulin"                  "BMI"                     
## [7] "DiabetesPedigreeFunction" "Age"                     
## 
## attr(,"class")
## [1] "NaiveBayes"
#Plot model
plot(model)

Predict testing set’s data into model

Evaluate outcome using accuracy

#Feature Scaling
train_scale <- scale(data_train[ ,1:8])
test_scale <- scale(data_test[ ,1:8])

#Predict on test data
y_pred <- predict(model, newdata=data_test)
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 1
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 2
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 3
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 4
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 5
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 6
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 7
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 8
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 9
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 10
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 11
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 12
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 13
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 14
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 15
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 16
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 17
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 18
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 19
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 20
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 21
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 22
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 23
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 24
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 25
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 26
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 27
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 28
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 29
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 30
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 31
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 32
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 33
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 34
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 35
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 36
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 37
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 38
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 39
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 40
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 41
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 42
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 43
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 44
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 45
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 46
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 47
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 48
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 49
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 50
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 51
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 52
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 53
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 54
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 55
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 56
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 57
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 58
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 59
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 60
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 61
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 62
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 63
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 64
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 65
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 66
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 67
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 68
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 69
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 70
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 71
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 72
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 73
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 74
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 75
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 76
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 77
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 78
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 79
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 80
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 81
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 82
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 83
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 84
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 85
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 86
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 87
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 88
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 89
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 90
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 91
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 92
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 93
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 94
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 95
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 96
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 97
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 98
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 99
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 100
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 101
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 102
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 103
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 104
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 105
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 106
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 107
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 108
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 109
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 110
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 111
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 112
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 113
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 114
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 115
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 116
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 117
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 118
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 119
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 120
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 121
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 122
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 123
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 124
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 125
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 126
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 127
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 128
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 129
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 130
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 131
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 132
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 133
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 134
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 135
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 136
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 137
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 138
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 139
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 140
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 141
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 142
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 143
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 144
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 145
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 146
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 147
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 148
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 149
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 150
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 151
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 152
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 153
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 154
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 155
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 156
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 157
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 158
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 159
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 160
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 161
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 162
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 163
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 164
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 165
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 166
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 167
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 168
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 169
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 170
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 171
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 172
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 173
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 174
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 175
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 176
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 177
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 178
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 179
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 180
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 181
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 182
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 183
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 184
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 185
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 186
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 187
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 188
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 189
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 190
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 191
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 192
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 193
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 194
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 195
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 196
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 197
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 198
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 199
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 200
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 201
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 202
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 203
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 204
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 205
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 206
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 207
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 208
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 209
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 210
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 211
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 212
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 213
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 214
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 215
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 216
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 217
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 218
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 219
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 220
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 221
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 222
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 223
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 224
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 225
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 226
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 227
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 228
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 229
## Warning in FUN(X[[i]], ...): Numerical 0 probability for all classes with
## observation 230
summary(data_test$Outcome)
##   0   1 
## 150  80
summary(y_pred$class)
##   0   1 
## 170  60
#Build Confusion Matrix
cm <- table(data_test$Outcome, y_pred$class)
cm
##    
##       0   1
##   0 131  19
##   1  39  41
#Model evaluation
confusionMatrix(cm)
## Confusion Matrix and Statistics
## 
##    
##       0   1
##   0 131  19
##   1  39  41
##                                           
##                Accuracy : 0.7478          
##                  95% CI : (0.6865, 0.8026)
##     No Information Rate : 0.7391          
##     P-Value [Acc > NIR] : 0.4154          
##                                           
##                   Kappa : 0.4097          
##                                           
##  Mcnemar's Test P-Value : 0.0126          
##                                           
##             Sensitivity : 0.7706          
##             Specificity : 0.6833          
##          Pos Pred Value : 0.8733          
##          Neg Pred Value : 0.5125          
##              Prevalence : 0.7391          
##          Detection Rate : 0.5696          
##    Detection Prevalence : 0.6522          
##       Balanced Accuracy : 0.7270          
##                                           
##        'Positive' Class : 0               
## 
#Accuracy achieved using Naive Bayes model is 74.78%, above the baseline accuracy of 65%.