Skip to content

function to get prediction columns #1224

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

Merged
merged 5 commits into from
Dec 8, 2024
Merged

function to get prediction columns #1224

merged 5 commits into from
Dec 8, 2024

Conversation

topepo
Copy link
Member

@topepo topepo commented Dec 4, 2024

In service of tidymodels/workflows#273

For a fitted model or workflow, return the column names that will contain predictions for the main types given by augment().

Tests for censored regression models and workflows will be in extratests

@topepo topepo marked this pull request as ready for review December 4, 2024 18:07
@topepo topepo requested a review from EmilHvitfeldt December 4, 2024 18:07
res$probabilities <- ".pred"
}
} else {
cli::cli_abort("Unsupported model mode {model_mode}.")
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know that this branch of the if/then will ever be encountered, given the error check above. However, we might hit is when we have a mode for quantile regression data so I'd err on the side of leaving it in, untested.

Copy link
Member

Choose a reason for hiding this comment

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

i think that is reasonable

topepo added a commit to tidymodels/extratests that referenced this pull request Dec 4, 2024
Copy link
Member

@EmilHvitfeldt EmilHvitfeldt left a comment

Choose a reason for hiding this comment

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

looking good. very clean

Co-authored-by: Emil Hvitfeldt <emil.hvitfeldt@posit.co>
@topepo topepo merged commit 27df158 into main Dec 8, 2024
12 checks passed
@topepo topepo deleted the prediction-columns branch December 8, 2024 13:34
#'
#' .get_prediction_column_names(lr_fit)
#' .get_prediction_column_names(lr_fit, syms = TRUE)
#' @export
Copy link
Member

Choose a reason for hiding this comment

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

Could we make this function @keyword internal?

Comment on lines +604 to +606
if (inherits(x, "workflow")) {
x <- x %>% extract_fit_parsnip(x)
}
Copy link
Member

Choose a reason for hiding this comment

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

With an eye toward the release cascade and trying to keep things as modular as possible, I think it would be good to make this function only for model_spec objects. This call to extract_fit_parsnip() seems to be all that's necessary for workflow objects. I'd move that to workflows or wherever this is going to be needed.

if (length(predict_types) == 0) {
cli::cli_abort("Prediction information could not be found for this
{.fn {model_type}} with engine {.val {model_engine}} and mode
{.val {model_mode}}. Does a parsnip extension package need to
Copy link
Member

Choose a reason for hiding this comment

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

That last question would be very nice in an i bullet rather than the error message itself.

)

unk_fit <- ols_fit
unk_fit$spec$mode <- "Depeche"
Copy link
Member

Choose a reason for hiding this comment

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

😆

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 Dec 25, 2024
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.

3 participants