Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize group arguments in functions #105

Merged
merged 21 commits into from
May 12, 2023
Merged

Standardize group arguments in functions #105

merged 21 commits into from
May 12, 2023

Conversation

EmilHvitfeldt
Copy link
Member

@EmilHvitfeldt EmilHvitfeldt commented May 9, 2023

This PR aims to tackle part of #104. Change 1 specifically.

While it might seems strange, I'm sticking with group over .by, as it is consistent with the existing codebase. Once this is done, I will swap everything over to .by as part of Change 2.

  • add group argument to cal_estimate_*.data.frame() functions
  • add group argument to cal_plot_.*.data.frame() functions
  • Handle .config in call_estimate_*.tune_results()` functions
  • Handle .config in call_plot_*.tune_results()` functions

Comment on lines 37 to 43
...,
group = NULL) {
stop_null_parameters(parameters)

check_group_argument({{ group }}, .data)
.data <- dplyr::group_by(.data, dplyr::across({{ group }}))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All *.data.frame() functions calls check_group_argument() and applies dplyr::group_by() with the group. This does nothing if group = NULL

Comment on lines -146 to +155
group <- expr(.config)
}

cal_plot_breaks_impl(
tune_args <- tune_results_args(
.data = .data,
truth = {{ truth }},
estimate = {{ estimate }},
group = {{ group }},
event_level = event_level,
...
)

cal_plot_breaks_impl(
.data = tune_args$predictions,
truth = !!tune_args$truth,
estimate = !!tune_args$estimate,
group = !!tune_args$group,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All *tune.results() are changed to use tune_results_args().

Comment on lines +94 to +96
if (quo_is_null(group)) {
.data[[".config"]] <- NULL
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there isn't a group variable, e.i. .config is constant, it is removed from the plotting data.

This makes it easier to test that faceting isn't done with constant .config

Comment on lines +251 to 255
if (dplyr::n_distinct(.data[[".predictions"]][[1]][[".config"]]) > 1) {
group <- quo(.config)
} else {
group <- quo(NULL)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the part that detects if there are more than 1 unique .config

@EmilHvitfeldt EmilHvitfeldt requested a review from topepo May 10, 2023 01:39
@topepo
Copy link
Member

topepo commented May 10, 2023

For multinomial outcomes, much (but not all) of the infrastructure make a series of 1:all problems and applies binomial methods.

While the automatic detection of .config works for binomial, it doesn't find it for multinomial:

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_windowed(truth = obs, VF:L)
#> Error in hpc_cv %>% mutate(.config = sample(letters[1:2], nrow(hpc_cv), : could not find function "%>%"

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_breaks(truth = obs, VF:L)
#> Error in hpc_cv %>% mutate(.config = sample(letters[1:2], nrow(hpc_cv), : could not find function "%>%"



library(tidymodels)
library(probably)
#> 
#> Attaching package: 'probably'
#> The following objects are masked from 'package:base':
#> 
#>     as.factor, as.ordered
tidymodels_prefer()
theme_set(theme_bw())
options(pillar.advice = FALSE, pillar.min_title_chars = Inf)
hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_windowed(truth = obs, VF:L)

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_breaks(truth = obs, VF:L)

Created on 2023-05-10 with reprex v2.0.2

(using group = .config does work though).

3 similar comments
@topepo
Copy link
Member

topepo commented May 10, 2023

For multinomial outcomes, much (but not all) of the infrastructure make a series of 1:all problems and applies binomial methods.

While the automatic detection of .config works for binomial, it doesn't find it for multinomial:

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_windowed(truth = obs, VF:L)
#> Error in hpc_cv %>% mutate(.config = sample(letters[1:2], nrow(hpc_cv), : could not find function "%>%"

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_breaks(truth = obs, VF:L)
#> Error in hpc_cv %>% mutate(.config = sample(letters[1:2], nrow(hpc_cv), : could not find function "%>%"



library(tidymodels)
library(probably)
#> 
#> Attaching package: 'probably'
#> The following objects are masked from 'package:base':
#> 
#>     as.factor, as.ordered
tidymodels_prefer()
theme_set(theme_bw())
options(pillar.advice = FALSE, pillar.min_title_chars = Inf)
hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_windowed(truth = obs, VF:L)

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_breaks(truth = obs, VF:L)

Created on 2023-05-10 with reprex v2.0.2

(using group = .config does work though).

@topepo
Copy link
Member

topepo commented May 10, 2023

For multinomial outcomes, much (but not all) of the infrastructure make a series of 1:all problems and applies binomial methods.

While the automatic detection of .config works for binomial, it doesn't find it for multinomial:

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_windowed(truth = obs, VF:L)
#> Error in hpc_cv %>% mutate(.config = sample(letters[1:2], nrow(hpc_cv), : could not find function "%>%"

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_breaks(truth = obs, VF:L)
#> Error in hpc_cv %>% mutate(.config = sample(letters[1:2], nrow(hpc_cv), : could not find function "%>%"



library(tidymodels)
library(probably)
#> 
#> Attaching package: 'probably'
#> The following objects are masked from 'package:base':
#> 
#>     as.factor, as.ordered
tidymodels_prefer()
theme_set(theme_bw())
options(pillar.advice = FALSE, pillar.min_title_chars = Inf)
hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_windowed(truth = obs, VF:L)

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_breaks(truth = obs, VF:L)

Created on 2023-05-10 with reprex v2.0.2

(using group = .config does work though).

@topepo
Copy link
Member

topepo commented May 10, 2023

For multinomial outcomes, much (but not all) of the infrastructure make a series of 1:all problems and applies binomial methods.

While the automatic detection of .config works for binomial, it doesn't find it for multinomial:

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_windowed(truth = obs, VF:L)
#> Error in hpc_cv %>% mutate(.config = sample(letters[1:2], nrow(hpc_cv), : could not find function "%>%"

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_breaks(truth = obs, VF:L)
#> Error in hpc_cv %>% mutate(.config = sample(letters[1:2], nrow(hpc_cv), : could not find function "%>%"



library(tidymodels)
library(probably)
#> 
#> Attaching package: 'probably'
#> The following objects are masked from 'package:base':
#> 
#>     as.factor, as.ordered
tidymodels_prefer()
theme_set(theme_bw())
options(pillar.advice = FALSE, pillar.min_title_chars = Inf)
hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_windowed(truth = obs, VF:L)

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_breaks(truth = obs, VF:L)

Created on 2023-05-10 with reprex v2.0.2

(using group = .config does work though).

@EmilHvitfeldt
Copy link
Member Author

That should be fixed now

library(tidymodels)
library(probably)
#> 
#> Attaching package: 'probably'
#> The following objects are masked from 'package:base':
#> 
#>     as.factor, as.ordered

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_windowed(truth = obs, VF:L)

hpc_cv %>%
  mutate(.config = sample(letters[1:2], nrow(hpc_cv), replace = TRUE)) %>% 
  cal_plot_breaks(truth = obs, VF:L)

Created on 2023-05-11 with reprex v2.0.2

@topepo topepo merged commit 88ef667 into main May 12, 2023
@topepo topepo deleted the groups branch May 12, 2023 00:04
@github-actions
Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants