Skip to content

Handle single prediction case for multinomial glmnet #428

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 2 commits into from
Feb 9, 2021

Conversation

juliasilge
Copy link
Member

This PR fixes the multinomial glmnet prediction for the single observation case that, it turns out, was half-fixed in #395. I did not realize it was only half-fixed because of how those post operations are not really loaded as functions and the test I wrote in extratests didn't start getting run until just now when we fixed the version number in the DESCRIPTION file.

So now this fixes it for real:

library(parsnip)

data("hpc_data", package = "modeldata")
hpc <- hpc_data[, c(2:5, 8)]

xy_fit <- fit_xy(
  multinom_reg(penalty = 0.1) %>% set_engine("glmnet"),
  x = hpc[, 1:4],
  y = hpc$class
)

predict(xy_fit, hpc[3, 1:4], type = "class")
#> # A tibble: 1 x 1
#>   .pred_class
#>   <fct>      
#> 1 VF
predict(xy_fit, hpc[3, 1:4], type = "prob")
#> # A tibble: 1 x 4
#>   .pred_VF .pred_F .pred_M .pred_L
#>      <dbl>   <dbl>   <dbl>   <dbl>
#> 1    0.531   0.298   0.114  0.0574

predict(xy_fit, hpc[10:11, 1:4], type = "class")
#> # A tibble: 2 x 1
#>   .pred_class
#>   <fct>      
#> 1 VF         
#> 2 VF
predict(xy_fit, hpc[10:11, 1:4], type = "prob")
#> # A tibble: 2 x 4
#>   .pred_VF .pred_F .pred_M .pred_L
#>      <dbl>   <dbl>   <dbl>   <dbl>
#> 1    0.524   0.302   0.115  0.0581
#> 2    0.524   0.302   0.115  0.0581

Created on 2021-02-09 by the reprex package (v1.0.0)

@topepo topepo merged commit 40274d6 into master Feb 9, 2021
@topepo topepo deleted the more-glmnet-cleanup branch February 9, 2021 18:47
@topepo
Copy link
Member

topepo commented Feb 9, 2021

Thanks!

@github-actions
Copy link

github-actions bot commented Mar 6, 2021

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 Mar 6, 2021
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