I'm currently reading chapter 4 of An Introduction to Statistical Learning by James et alter. I've been trying to go through the examples myself, replicating the calculations in R. Section $(4.4.4)$ is about Naive Bayes classification and it's application to the ISLR2 Default dataset; results are summed up in the following table
However, I can't manage to obtain the same results in R, using the naiveBayes command from e1071 library. Here is my code
>>library(ISLR2) >>library(e1071) >>nb.fit <- naiveBayes(default~student+balance,data=Default) >>nb.class <- predict(nb.fit,Default) >>table(nb.class,Default$default) nb.class No Yes No 9621 244 Yes 46 89
The two tables are not that different, but having used the same exact data I would expect to get the results to be completely equal. Is there actually an issue in my code?
By the way, I'm using R version 4.3.1