October 2017
Beginner to intermediate
572 pages
26h 1m
English
If you wish to perform the k-fold validation with the use of other models, simply replace the line to generate the fit variable to whatever classifier you prefer. For example, if you would like to assess the Naïve Bayes model with a 10-fold cross-validation, you just need to replace the calling function from svm to naiveBayes:
> for (i in 1:10) {
+ fit = naiveBayes(churn ~., churnTrain[ind != i,])
+ predictions = predict(fit, churnTrain[ind == i, ! names(churnTrain) %in% c("churn")])
+ correct_count = sum(predictions == churnTrain[ind == i,c("churn")])
+ accuracies = append(correct_count / nrow(churnTrain[ind == i,]), accuracies)
+ }
Read now
Unlock full access