You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/articles/Examples.Rmd
+151Lines changed: 151 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,81 @@ These examples show how to *fit* and *predict* with different combinations of mo
24
24
The following examples use consistent data sets throughout. For regression, we use the Chicago ridership data. For classification, we use an artificial data set for a binary example and the Palmer penguins data for a multiclass example.
25
25
26
26
27
+
## `bart()` models
28
+
29
+
<detailsid="bart-dbarts">
30
+
31
+
<summary>With the `"dbarts"` engine</summary>
32
+
33
+
<h3>Regression Example (`dbarts`)</h3>
34
+
35
+
```{r echo=FALSE}
36
+
knitr::spin_child("template-reg-chicago.R")
37
+
```
38
+
39
+
We can define the model with specific parameters:
40
+
41
+
```{r}
42
+
bt_reg_spec <-
43
+
bart(trees = 15) %>%
44
+
# This model can be used for classification or regression, so set mode
45
+
set_mode("regression") %>%
46
+
set_engine("dbarts")
47
+
bt_reg_spec
48
+
```
49
+
50
+
Now we create the model fit object:
51
+
52
+
```{r}
53
+
set.seed(1)
54
+
bt_reg_fit <- bt_reg_spec %>% fit(ridership ~ ., data = Chicago_train)
55
+
bt_reg_fit
56
+
```
57
+
58
+
The holdout data can be predicted:
59
+
60
+
```{r}
61
+
predict(bt_reg_fit, Chicago_test)
62
+
```
63
+
64
+
65
+
<h3>Classification Example (`dbarts`)</h3>
66
+
67
+
```{r echo=FALSE}
68
+
knitr::spin_child("template-cls-two-class.R")
69
+
```
70
+
71
+
We can define the model with specific parameters:
72
+
73
+
```{r}
74
+
bt_cls_spec <-
75
+
bart(trees = 15) %>%
76
+
# This model can be used for classification or regression, so set mode
77
+
set_mode("classification") %>%
78
+
set_engine("dbarts")
79
+
bt_cls_spec
80
+
```
81
+
82
+
Now we create the model fit object:
83
+
84
+
```{r}
85
+
set.seed(1)
86
+
bt_cls_fit <- bt_cls_spec %>% fit(Class ~ ., data = data_train)
87
+
bt_cls_fit
88
+
```
89
+
90
+
The holdout data can be predicted for both hard class predictions and probabilities. We'll bind these together into one tibble:
91
+
92
+
```{r}
93
+
bind_cols(
94
+
predict(bt_cls_fit, data_test),
95
+
predict(bt_cls_fit, data_test, type = "prob")
96
+
)
97
+
```
98
+
99
+
</details>
100
+
101
+
27
102
## `boost_tree()` models
28
103
29
104
<detailsid="boost-tree-xgboost">
@@ -252,6 +327,82 @@ The following examples use consistent data sets throughout. For regression, we u
0 commit comments