Skip to content

predict() on a multinomial regression with glmnet double names the output with .pred_ #107

Closed
@DavisVaughan

Description

@DavisVaughan

i.e.

library(parsnip)
data("lending_club")

multi_reg <- multinom_reg(penalty = 0.01)
multi_reg_glmnet <- multi_reg %>% set_engine("glmnet")
multi_reg_fit <- fit(multi_reg_glmnet, verification_status ~ annual_inc + sub_grade, data = lending_club)

multi_reg_fit %>%
    predict(new_data = lending_club, type = "prob")
#> # A tibble: 9,857 x 3
#>    .pred_.pred_Not_Verified .pred_.pred_Source_Verified .pred_.pred_Verifi…
#>                       <dbl>                       <dbl>               <dbl>
#>  1                    0.312                       0.389               0.298
#>  2                    0.365                       0.369               0.266
#>  3                    0.341                       0.383               0.277
#>  4                    0.297                       0.416               0.287
#>  5                    0.387                       0.377               0.236
#>  6                    0.305                       0.387               0.308
#>  7                    0.366                       0.366               0.268
#>  8                    0.409                       0.397               0.194
#>  9                    0.365                       0.380               0.255
#> 10                    0.370                       0.360               0.270
#> # … with 9,847 more rows

This is simply due to this line:

https://github.com/tidymodels/parsnip/blob/master/R/multinom_reg_data.R#L47

We don't need to add .pred_ to the names here, as it is done once in the formatting step at the end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions