Skip to content

Commit

Permalink
fixing inconsistent train/test split in reg1,2
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorcampbell committed Nov 14, 2023
1 parent 154a7fb commit 0ee258a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions source/regression1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ that we used earlier in the chapter (Figure \@ref(fig:07-small-eda-regr)).
\index{training data}
\index{test data}

```{r 07-sacramento-seed-before-train-test-split, echo = FALSE, message = FALSE, warning = FALSE}
# hidden seed -- make sure this is the same as what appears in reg2 right before train/test split
set.seed(10)
```

```{r 07-test-train-split}
sacramento_split <- initial_split(sacramento, prop = 0.75, strata = price)
sacramento_train <- training(sacramento_split)
Expand Down
7 changes: 4 additions & 3 deletions source/regression2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ can come back to after we choose our final model. Let's take care of that now.
library(tidyverse)
library(tidymodels)
set.seed(1234)
set.seed(10)
sacramento <- read_csv("data/sacramento.csv")
sacramento_split <- initial_split(sacramento, prop = 0.6, strata = price)
sacramento_split <- initial_split(sacramento, prop = 0.75, strata = price)
sacramento_train <- training(sacramento_split)
sacramento_test <- testing(sacramento_split)
```
Expand Down Expand Up @@ -349,7 +349,8 @@ obtained from the same problem, shown in Figure \@ref(fig:08-compareRegression).

```{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."}
set.seed(1234)
sacr_spec <- nearest_neighbor(weight_func = "rectangular", neighbors = 30) |>
# neighbors = 28 from regression1 chapter
sacr_spec <- nearest_neighbor(weight_func = "rectangular", neighbors = 28) |>
set_engine("kknn") |>
set_mode("regression")
Expand Down

0 comments on commit 0ee258a

Please sign in to comment.