Skip to content

Commit 0ee258a

Browse files
fixing inconsistent train/test split in reg1,2
1 parent 154a7fb commit 0ee258a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

source/regression1.Rmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ that we used earlier in the chapter (Figure \@ref(fig:07-small-eda-regr)).
305305
\index{training data}
306306
\index{test data}
307307

308+
```{r 07-sacramento-seed-before-train-test-split, echo = FALSE, message = FALSE, warning = FALSE}
309+
# hidden seed -- make sure this is the same as what appears in reg2 right before train/test split
310+
set.seed(10)
311+
```
312+
308313
```{r 07-test-train-split}
309314
sacramento_split <- initial_split(sacramento, prop = 0.75, strata = price)
310315
sacramento_train <- training(sacramento_split)

source/regression2.Rmd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ can come back to after we choose our final model. Let's take care of that now.
221221
library(tidyverse)
222222
library(tidymodels)
223223
224-
set.seed(1234)
224+
set.seed(10)
225225
226226
sacramento <- read_csv("data/sacramento.csv")
227227
228-
sacramento_split <- initial_split(sacramento, prop = 0.6, strata = price)
228+
sacramento_split <- initial_split(sacramento, prop = 0.75, strata = price)
229229
sacramento_train <- training(sacramento_split)
230230
sacramento_test <- testing(sacramento_split)
231231
```
@@ -349,7 +349,8 @@ obtained from the same problem, shown in Figure \@ref(fig:08-compareRegression).
349349

350350
```{r 08-compareRegression, echo = FALSE, warning = FALSE, message = FALSE, fig.height = 4.75, fig.width = 10, fig.cap = "Comparison of simple linear regression and KNN regression."}
351351
set.seed(1234)
352-
sacr_spec <- nearest_neighbor(weight_func = "rectangular", neighbors = 30) |>
352+
# neighbors = 28 from regression1 chapter
353+
sacr_spec <- nearest_neighbor(weight_func = "rectangular", neighbors = 28) |>
353354
set_engine("kknn") |>
354355
set_mode("regression")
355356

0 commit comments

Comments
 (0)