Skip to content

Instantly share code, notes, and snippets.

@ridwanbejo
Last active January 15, 2019 09:55
Show Gist options
  • Save ridwanbejo/1e6c0e5fd0a972e62d3ee6e0080f374e to your computer and use it in GitHub Desktop.
Save ridwanbejo/1e6c0e5fd0a972e62d3ee6e0080f374e to your computer and use it in GitHub Desktop.
naive bayes classification with cv
library(e1071)
library(gmodels)
library(caret)
# 1. Load dataset from CSV
bank_csv <- read.csv("./Downloads/bank-additional/bank-additional-full.csv", header=TRUE, sep=";")
bank_df <- as.data.frame(bank_csv[1:32951,])
summary(bank_df)
# 2. Do the preprocessing
# 2.1. todo
# 2.2. todo
# 2.3. todo
# 2.4. todo
# 3. Train the model
model <- naiveBayes(bank_df, bank_df$y, 'nb', laplace=1, trControl=trainControl(method='cv',number=50))
# 4. Test the model
term_deposit_test <- predict(model, bank_csv[32952:41188,1:20])
# 5. Evaluate the model
CrossTable(term_deposit_test, bank_csv[32952:41188,21], prop.chisq = FALSE, prop.t = FALSE, dnn = c('predicted', 'actual'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment