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
@@ -29,7 +39,7 @@ Modeling or machine learning in R can result in fitted model objects that take u
29
39
1. Heavy usage of formulas and closures that capture the enclosing environment in model training
30
40
2. Lack of selectivity in the construction of the model object itself
31
41
32
-
As a result, fitted model objects contain components that are often redundant and not required for post-fit estimation activities. The butcher package provides tooling to "axe" parts of the fitted output that are no longer needed, without sacrificing prediction functionality from the original model object.
42
+
As a result, fitted model objects contain components that are often redundant and not required for post-fit estimation activities. The butcher package provides tooling to "axe" parts of the fitted output that are no longer needed, without sacrificing prediction functionality from the original model object.
33
43
34
44
## Installation
35
45
@@ -46,33 +56,33 @@ Or install the development version from [GitHub](https://github.com/):
46
56
pak::pak("tidymodels/butcher")
47
57
```
48
58
49
-
## Butchering
59
+
## Butchering
50
60
51
-
As an example, let's wrap an `lm` model so it contains a lot of unnecessary stuff:
61
+
As an example, let's wrap an `lm` model so it contains a lot of unnecessary stuff:
52
62
53
63
```{r example}
54
64
library(butcher)
55
65
our_model <- function() {
56
66
some_junk_in_the_environment <- runif(1e6) # we didn't know about
57
-
lm(mpg ~ ., data = mtcars)
67
+
lm(mpg ~ ., data = mtcars)
58
68
}
59
69
```
60
70
61
-
This object is unnecessarily large:
71
+
This object is unnecessarily large:
62
72
63
73
```{r}
64
74
library(lobstr)
65
75
obj_size(our_model())
66
76
```
67
77
68
-
When, in fact, it should only be:
78
+
When, in fact, it should only be:
69
79
70
80
```{r}
71
-
small_lm <- lm(mpg ~ ., data = mtcars)
81
+
small_lm <- lm(mpg ~ ., data = mtcars)
72
82
obj_size(small_lm)
73
83
```
74
84
75
-
To understand which part of our original model object is taking up the most memory, we leverage the `weigh()` function:
85
+
To understand which part of our original model object is taking up the most memory, we leverage the `weigh()` function:
76
86
77
87
```{r}
78
88
big_lm <- our_model()
@@ -113,8 +123,8 @@ Check out the `vignette("available-axe-methods")` to see butcher's current cover
113
123
114
124
1. Run `new_model_butcher(model_class = "your_object", package_name = "your_package")`
115
125
2. Use butcher helper functions `weigh()` and `locate()` to decide what to axe
116
-
3. Finalize edits to `R/your_object.R` and `tests/testthat/test-your_object.R`
117
-
4. Make a pull request!
126
+
3. Finalize edits to `R/your_object.R` and `tests/testthat/test-your_object.R`
0 commit comments