# Naive Bayes with R - ISLR Default dataset

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

## 1 Answer

No issues with your code! You can find the Errata for the second edition of ISLR on the main site of the book: https://www.statlearning.com/errata-second-edition.

For this particular problem you will be able to reproduce the results for table 4.8. by also using "income" as a predictor. The Errata says:

Page 156, Table 4.8: this table results from including Income as a covariate. However, earlier results in this chapter did not include Income as a covariate. When Income is not included as a covariate, the 1st 2 rows of this table are as follows:

Predicted default status = No: 9621 244 9865

Predicted default status = Yes: 46 89 135

• Thanks a lot, I was really losing my mind on that Jul 28 at 17:16
• Could you quote what the errata says in your answer so it is self-explanatory?
– Tim
Jul 28 at 22:22