# Estimate accuracy using repeated k-fold cross validation.

# load the library
library(caret)
# load the iris dataset
data(iris)

# define an 70%/30% train/test split of the dataset
split=0.70
trainIndex <- createDataPartition(iris$Species, p=split, list=FALSE)
data_train <- iris[ trainIndex,]
data_test  <- iris[-trainIndex,]


# define training control
train_control <- trainControl(method="repeatedcv", number=10, repeats=5)

# train the model
model <- train(Species~., data=data_train, trControl=train_control, method="nb")
# summarize results
print(model)



# make predictions
predictions <- predict(model, data_test[,1:4]) 

# summarize results
confusionMatrix(predictions, data_test$Species)
