-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-model.qmd
91 lines (63 loc) · 1.81 KB
/
01-model.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
title: "01-model"
format: html
---
```{r setup, include=FALSE}
options(scipen = 999)
library(tidyverse)
library(tidymodels)
# update rcis if the package is not up-to-date - only way to access bechdel
# remotes::install_github("cis-ds/rcis")
library(rcis)
data("bechdel")
bechdel
```
# Your Turn 1
Run the chunk below and look at the output. Then, copy/paste the code and edit to create:
+ a decision tree model for classification
+ that uses the `C5.0` engine.
Save it as `tree_mod` and look at the object. What is different about the output?
*Hint: you'll need https://www.tidymodels.org/find/parsnip/*
```{r}
lr_mod <- logistic_reg() %>%
set_engine(engine = "glm") %>%
set_mode("classification")
lr_mod
```
```{r}
```
# Your Turn 2
Fill in the blanks.
Use `initial_split()`, `training()`, and `testing()` to:
1. Split **bechdel** into training and test sets. Save the rsplit!
2. Extract the training data and fit your classification tree model.
3. Check the proportions of the `test` variable in each set.
Keep `set.seed(100)` at the start of your code.
*Hint: Be sure to remove every `_` before running the code!*
```{r}
set.seed(100) # Important!
bechdel_split <- ________(bechdel, strata = test, prop = 3 / 4)
bechdel_train <- ________(bechdel_split)
bechdel_test <- ________(bechdel_split)
```
## Your Turn 3
Run the code below. What does it return?
```{r}
set.seed(100)
bechdel_folds <- vfold_cv(data = bechdel_train, v = 10, strata = test)
bechdel_folds
```
## Your Turn 4
Add a `autoplot()` to visualize the ROC AUC.
```{r}
tree_preds <- tree_mod %>%
fit_resamples(
test ~ metascore + imdb_rating,
resamples = bechdel_folds,
control = control_resamples(save_pred = TRUE)
)
tree_preds %>%
collect_predictions() %>%
roc_curve(truth = test, .pred_Fail) %>%
________()
```