Repository navigation
add butcher methods for nestedmodels - #256
Conversation
juliasilge
left a comment
There was a problem hiding this comment.
Thank you so much for this contribution @ashbythorpe! 🙌 I've got a couple of questions about how you set this up.
| verbose = FALSE, | ||
| ... | ||
| ) | ||
| all_disabled <- purrr::map(x$fit$.model_fit, attr, "disabled") |
There was a problem hiding this comment.
Can you tell me more about how the disabled methods are intended to be found here? I don't seem to find this working for me:
library(butcher)
model <- nestedmodels::nested(
parsnip::set_engine(parsnip::linear_reg(), "lm")
)
nested_data <- tidyr::nest(nestedmodels::example_nested_data, data = -id)
fit <- parsnip::fit(model, z ~ x + y + a + b, nested_data)
fit$fit$.model_fit <- purrr::map(
fit$fit$.model_fit,
axe_fitted,
verbose = TRUE
)
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
#> ✔ Memory released: "0 B"
purrr::map(fit$fit$.model_fit, attr, "disabled")
#> [[1]]
#> NULL
#>
#> [[2]]
#> NULL
#>
#> [[3]]
#> NULL
#>
#> [[4]]
#> NULL
#>
#> [[5]]
#> NULL
#>
#> [[6]]
#> NULL
#>
#> [[7]]
#> NULL
#>
#> [[8]]
#> NULL
#>
#> [[9]]
#> NULL
#>
#> [[10]]
#> NULL
#>
#> [[11]]
#> NULL
#>
#> [[12]]
#> NULL
#>
#> [[13]]
#> NULL
#>
#> [[14]]
#> NULL
#>
#> [[15]]
#> NULL
#>
#> [[16]]
#> NULL
#>
#> [[17]]
#> NULL
#>
#> [[18]]
#> NULL
#>
#> [[19]]
#> NULL
#>
#> [[20]]
#> NULLCreated on 2023-03-17 with reprex v2.0.2
|
Apologies, I think I should have been more clear about what I was doing with the verbose option. Since in the "nested_model_fit" object, all the inner models are the same type of model, the functions disabled by each axing function will be the same for every inner model. As a result, my idea was to create a summary of these models, outputting the functions disabled for every inner model and the total memory released, rather than having a separate message for each model. A similar thing is done in ipred.R (except there the disabled methods are already known). This example demonstrates this (the previous commit should have fixed the issue with the "butcher_disabled" attribute). library(nestedmodels)
library(parsnip)
model <- linear_reg() %>%
set_engine("lm") %>%
nested()
nested_data <- tidyr::nest(example_nested_data, data = -id)
fit <- fit(model, z ~ x + y + a + b, nested_data)
res <- axe_call(fit, verbose = TRUE)
#> ✔ Memory released: "8.47 kB"
#> ✖ Disabled: `print()` and `summary()`
res <- axe_fitted(fit, verbose = TRUE)
#> ✔ Memory released: "5.71 kB"
#> ✖ Disabled: `fitted()` and `summary()`
res <- butcher(fit, verbose = TRUE)
#> ✔ Memory released: "61.96 kB"
#> ✖ Disabled: `print()`, `summary()`, and `fitted()`
# To compare, this is the result of axing one inner model
inner_model <- fit$fit$.model_fit[[5]]$fit
res <- axe_call(inner_model, verbose = TRUE)
#> ✔ Memory released: "920 B"
#> ✖ Disabled: `print()` and `summary()`
res <- axe_fitted(inner_model, verbose = TRUE)
#> ✔ Memory released: "80 B"
#> ✖ Disabled: `fitted()` and `summary()`
res <- butcher(inner_model, verbose = TRUE)
#> ✔ Memory released: "3.92 kB"
#> ✖ Disabled: `print()`, `summary()`, and `fitted()`Let me know if you think it would be better to show the full output to the user. |
juliasilge
left a comment
There was a problem hiding this comment.
Yes OK, makes sense to me now, and thank you for fixing the disabled methods! 🙌
|
This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
A simple set of methods for
nested_model_fitobjects, just iterates through all the inner models and callsaxe_()on them.