From 0107b1f7c73443dd98591ad3655bf458cfd2e46b Mon Sep 17 00:00:00 2001 From: simonpcouch Date: Tue, 10 May 2022 10:22:40 -0400 Subject: [PATCH] start basics vignette --- .gitignore | 1 + DESCRIPTION | 5 +++- vignettes/.gitignore | 2 ++ vignettes/bonsai.Rmd | 61 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 vignettes/.gitignore create mode 100644 vignettes/bonsai.Rmd diff --git a/.gitignore b/.gitignore index 234f028..0d7f03b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .RData .Ruserdata docs +inst/doc diff --git a/DESCRIPTION b/DESCRIPTION index 36e6812..9eea505 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,7 +31,9 @@ Suggests: partykit, modeldata, covr, - testthat (>= 3.0.0) + testthat (>= 3.0.0), + knitr, + rmarkdown Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) @@ -39,3 +41,4 @@ RoxygenNote: 7.1.2.9000 URL: https://bonsai.tidymodels.org/, https://github.com/tidymodels/bonsai BugReports: https://github.com/tidymodels/bonsai/issues Config/Needs/website: tidyverse/tidytemplate +VignetteBuilder: knitr diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/bonsai.Rmd b/vignettes/bonsai.Rmd new file mode 100644 index 0000000..883a56f --- /dev/null +++ b/vignettes/bonsai.Rmd @@ -0,0 +1,61 @@ +--- +title: "Introduction to bonsai" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Introduction to bonsai} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +The goal of bonsai is to provide bindings for additional tree-based model engines for use with the {parsnip} package. + +If you're not familiar with parsnip, you can read more about the package on it's [website](https://parsnip.tidymodels.org). + +To get started, load bonsai with: + +```{r setup} +library(bonsai) +``` + +To illustrate how to use the package, we'll fit some models to a dataset containing measurements on 3 different species of penguins. Loading in that data and checking it out: + +```{r} +library(modeldata) + +data(penguins) + +str(penguins) +``` + +Specifically, we'll make use of measurements on penguin's flippers, and the island that they live on, to predict their species using a decision tree. We'll do so using the engine `"partykit"`—this is one of the packages that bonsai supports that will be used to actually fit model parameter estimates. + + +```{r} +# set seed for reproducibility +set.seed(1) + +# specify and fit model +dec_mod <- + decision_tree() %>% + set_engine(engine = "partykit") %>% + set_mode(mode = "classification") %>% + fit( + formula = species ~ flipper_length_mm + island, + data = penguins + ) + +dec_mod +``` + +From this output, we can see that the model generally first looks to `island` to determine species, and then makes use of a mix of flipper length and island to ultimately make a species prediction. There are a total of `r ` terminal nodes in this tree. + +```{r} + +```