mlr-org / mlr3learners

Recommended learners for mlr3
https://mlr3learners.mlr-org.com
GNU Lesser General Public License v3.0
91 stars 16 forks source link

[glmnet, logreg] Positive class does not get passed correctly #196

Closed Coorsaa closed 3 years ago

Coorsaa commented 3 years ago

quick fix can be found in branch logreg_quick_fix

berndbischl commented 3 years ago

@Coorsaa but the issue is lacking a lot of info....

berndbischl commented 3 years ago

for reference here is my code, but you should have posted something similar

berndbischl commented 3 years ago

library(devtools)
library(data.table)
load_all("~/mlr3misc")
load_all("~/mlr3")
load_all("~/mlr3learners")
options(warn = -1)

lrn1 = lrn("classif.log_reg", predict_type = "prob")
task1 = tsk("sonar")
dd = task1$data()
# set first 3 true y to some known values
dd$Class[1:3] = c("R", "R", "M")
print("classes in df")
print(head(dd$Class, 3))

print("########### case pos=R ")
# this implies first 3 encoding should be 1,1,0
task2 = TaskClassif$new(backend = dd, target = "Class", id = "sonar2", positive = "R")
lrn1$train(task2)
m = lrn1$model
print("encoding in LR model")
print("should be 1,1,0")
print(head(m$y, 3))
# this is passed inthe learner into glm
# rdocs of glm state that the first level encodes failure=0
# also note that the order of the levels now has switched in the factor in data()
print(head(task2$data()$Class, 3))

print("########### case pos=M ")

# case2;  set pos = M
# this implies first 3 encoding should be 0,0,1
task2 = TaskClassif$new(backend = dd, target = "Class", id = "sonar2", positive = "M")
lrn1$train(task2)
m = lrn1$model
print("encoding in LR model")
print("should be 0,0,1")
 print(head(m$y, 3))
berndbischl commented 3 years ago

but this might be old news as michel already fixed log_reg. do you have a reprex for glmnet?

Coorsaa commented 3 years ago

both learners seem to work as expected now in my tests, depending on the positive class. this issuer can probably be closed imo.

berndbischl commented 3 years ago

thanks. @Coorsaa are you by any change aware of any other model where the internal coding would be important like this?

mllg commented 3 years ago

Fixed via fbb2275aa0b0f56eaba183a28b307d92999e6df1 and a2e18ebc8bfaf20a74f03ae1e4f24540c4c4f4a5.