2
$\begingroup$

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 tableenter image description here

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

$\endgroup$

1 Answer 1

2
$\begingroup$

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.