There are very complicated examples on the internet. I couldn't apply them to my codes. I have a dataset consisting 14 independent and 1 dependent variable. I'm making classification with R. Here is my code:
dataset <- read.table("adult.data", sep = ",", na.strings = c(" ?"))
colnames(dataset) <- c( "age",
"workclass",
"fnlwgt",
"education",
"education.num",
"marital.status",
"occupation",
"relationship",
"race",
"sex",
"capital.gain",
"capital.loss",
"hours.per.week",
"native.country",
"is.big.50k")
dataset = na.omit(dataset)
library(caret)
set.seed(1)
traning.indices <- createDataPartition(y = dataset$is.big.50k, p = 0.7, list = FALSE)
training.set <- dataset[traning.indices,]
test.set <- dataset[-traning.indices,]
###################################################################
## Naive Bayes
library(e1071)
classifier = naiveBayes(x = training.set[,-15],
y = training.set$is.big.50k)
prediction = predict(classifier, newdata = test.set[,-15])
cm <- confusionMatrix(data = prediction, reference = test.set[,15],
positive = levels(test.set$is.big.50k)[2])
accuracy <- sum(diag(as.matrix(cm))) / sum(as.matrix(cm))
sensitivity <- sensitivity(prediction, test.set[,15],
positive = levels(test.set$is.big.50k)[2])
specificity <- specificity(prediction, test.set[,15],
negative = levels(test.set$is.big.50k)[1])
I tried this. It worked. Is there any mistake? Is there any problem on transformation process? (on as.numeric() method)
library(ROCR)
pred <- prediction(as.numeric(prediction), as.numeric(test.set[,15]))
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, main = "ROC curve for NB",
col = "blue", lwd = 3)
abline(a = 0, b = 1, lwd = 2, lty = 2)
brms
R package? - patL