Skip to content

Comments

[docs] Details to performance_roc()#777

Merged
strengejacke merged 11 commits intomainfrom
docs_performance_roc
Dec 29, 2024
Merged

[docs] Details to performance_roc()#777
strengejacke merged 11 commits intomainfrom
docs_performance_roc

Conversation

@DominiqueMakowski
Copy link
Member

There is probably a better way to phrase it though (@mattansb?)

@mattansb
Copy link
Member

The docs look great (:

@DominiqueMakowski
Copy link
Member Author

why does the as.numeric() method fail?? It fails locally too, did I forgot how to R?

@strengejacke
Copy link
Member

For me, it also fails locally and I couldn't find any mistake? Strange, what have we missed?

@strengejacke
Copy link
Member

strengejacke commented Dec 29, 2024

performance:::as.numeric.performance_roc(x) works, as.numeric(x) not. @etiennebacher, any ideas, why the as.numeric.performance_roc() method in this PR does not work, resp. is not called?

library(performance)
library(bayestestR)
data(iris)

set.seed(123)
iris$y <- rbinom(nrow(iris), size = 1, .3)
folds <- sample(nrow(iris), size = nrow(iris) / 8, replace = FALSE)
test_data <- iris[folds, ]
train_data <- iris[-folds, ]

model <- glm(y ~ Sepal.Length + Sepal.Width, data = train_data, family = "binomial")
x <- performance_roc(model, new_data = test_data)

class(x)
#> [1] "performance_roc"     "see_performance_roc" "data.frame"

methods(class = class(x))
#> Warning in .S3methods(generic.function, class, envir, all.names = all.names, :
#> 'class' is of length > 1; only the first element will be used
#> [1] as.numeric plot       print     
#> see '?methods' for accessing help and source code

as.numeric(x)
#> Error: 'list' object cannot be coerced to type 'double'

performance:::as.numeric.performance_roc(x)
#> [1] 0.3766234

Created on 2024-12-29 with reprex v2.1.1

@etiennebacher
Copy link
Member

You need to add the S3 method for as.double.performance_roc instead of as.numeric.performance_roc. From ?as.numeric:

as.numeric is a generic function, but S3 methods must be written for as.double. It is identical to as.double.

@strengejacke
Copy link
Member

Coo, thanks!

@strengejacke strengejacke merged commit 46a0dae into main Dec 29, 2024
19 of 21 checks passed
@strengejacke strengejacke deleted the docs_performance_roc branch December 29, 2024 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants