In the Section 7.7 Underfitting and overfitting, the textbook says to fit a KNN regression model with neighbors=932 (the size of the entire dataset); however, in the code, fitting was done on only the training split (size=699). It will cause an error if we really use neighbors=932 since neighbors cannot be larger than the data size. (The code this error because it uses an if/else statement and does not actually fit neighbors=932, instead it takes the mean of all training samples, which is equivalent to using neighbors=699 where 699 is the training sample size).
In the Section 7.7 Underfitting and overfitting, the textbook says to fit a KNN regression model with
neighbors=932
(the size of the entire dataset); however, in the code, fitting was done on only the training split (size=699). It will cause an error if we really useneighbors=932
sinceneighbors
cannot be larger than the data size. (The code this error because it uses an if/else statement and does not actually fitneighbors=932
, instead it takes the mean of all training samples, which is equivalent to usingneighbors=699
where 699 is the training sample size).