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

Bugfix w.r.t. issue #185 #189

Merged
merged 1 commit into from
Apr 26, 2022
Merged

Bugfix w.r.t. issue #185 #189

merged 1 commit into from
Apr 26, 2022

Conversation

g-rho
Copy link
Contributor

@g-rho g-rho commented Apr 13, 2022

Hi Christoph,

the PR hopefully fixes issue #185 (which results from issue no.12 in github.com/LamaTe/mlr3shiny/).
The problem ist that ordered factors have two classes (ordered and factor) which results in an error when the function get.feature.type() is called within get.grid() (file utils.R).

It would be great if you could check and merge the PR such that we can close the related issue in our package.
Gero

(call function get.feature.type() within get.grid() in utils.R)
@christophM
Copy link
Collaborator

Thanks! Could you add a test that shows that it now works?

@pat-s
Copy link
Collaborator

pat-s commented Apr 25, 2022

The underlying problem here is that when an ordered factor is passed, class() returns two values "ordered", "factor" which in turn breaks some future length comparison.

Usually ones tries to avoid hardcoding such a [1] subsets in packages. Yet in this case it will solve the issue and avoid additional code refactoring.

Here's a reprex that uses the fix from @g-rho

library(mlr3)
library(mlr3learners)
library(mlr3pipelines)
library(iml)
# using pre-defined mlr3-tasks
task <- tsk("german_credit")

# create initial graph
graph <- Graph$new()
# adding learner PipeOp
graph$add_pipeop(lrn("classif.log_reg", predict_type = "prob"))

# graph <- graph %>>% po("threshold")
# graph$param_set$values$threshold.thresholds <- 0.5
# saving the graph as a GraphLearner
learner <- as_learner(graph)

# creating split for test and training data
# using default 80/20 split
train_ids <- sample(task$row_ids, task$nrow * 0.8)
test_ids <- setdiff(task$row_ids, train_ids)
# training the model
learner$train(task, row_ids = train_ids)
# predicting on the training and test data
train_pred <- learner$predict(task, row_ids = train_ids)
test_pred <- learner$predict(task, row_ids = test_ids)


# using iml for explaining
model <- Predictor$new(learner, data = task$data(), y = task$target_names)
feat_imp <- FeatureImp$new(model, loss = "ce", compare = "ratio")

# this one failed initially but works now
feat_effect <- FeatureEffects$new(model, method = "pdp")

Created on 2022-04-25 by the reprex package (v2.0.1)

@pat-s
Copy link
Collaborator

pat-s commented Apr 25, 2022

@christophM Could you merge main? (I can't myself, no perm)

You could also enable a setting the in repo settings to display a prompt to update the branch state.

@christophM christophM merged commit b7d2b3c into giuseppec:main Apr 26, 2022
@pat-s
Copy link
Collaborator

pat-s commented Apr 26, 2022

FWIW I actually meant to merge the main branch into this one so we can see the CI checks :)
But it seems they are happy in the main branch already, so all good.

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.

3 participants