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

GAM class prediction bug #541

Closed
topepo opened this issue Jul 30, 2021 · 3 comments
Closed

GAM class prediction bug #541

topepo opened this issue Jul 30, 2021 · 3 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@topepo
Copy link
Member

topepo commented Jul 30, 2021

library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip
tidymodels_prefer()

data("parabolic")

gam_spec <- gen_additive_mod() %>% set_mode("classification")
vars <- workflow_variables(outcomes = c(class), predictors = c(starts_with("X")))

wflow <- 
   workflow() %>% 
   add_model(gam_spec, formula = class ~ s(X1) + s(X2)) %>% 
   add_variables(variables = vars)

fit <- fit(wflow, parabolic)
predict(fit, parabolic[1:3, -3])
#> # A tibble: 3 x 1
#>   .pred_class
#>   <fct>      
#> 1 Class1     
#> 2 Class2     
#> 3 Class2

Created on 2021-07-30 by the reprex package (v2.0.0)

The issue is that mgcv returns a 1D array of class probabilities.

#   Browse[2]> 
#   debug: if (!is.null(object$spec$method$pred$class$post)) {
#       res <- object$spec$method$pred$class$post(res, object)
#   }
#   Browse[2]> res
#            1          2          3 
#   0.05420371 0.97374897 0.81707404 
#   Browse[2]> class(res)
#   [1] "array"
@topepo topepo added the bug an unexpected problem or unintended behavior label Jul 30, 2021
topepo added a commit that referenced this issue Jul 30, 2021
juliasilge added a commit that referenced this issue Jul 30, 2021
@DavisVaughan
Copy link
Member

should this be closed then?

@juliasilge
Copy link
Member

Yep!

Closed by #542

@github-actions
Copy link

This issue 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 Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants