mlr3pipelines
mlr3pipelines copied to clipboard
graphlearners doesn't work in conterfactual packages
My code is showed below:
prc_rf_lrn=lrn("classif.ranger",predict_type="prob",importance="impurity") graph_rf=prc_rf_lrn %>>% po("threshold") graph_rf$plot() learners_rf=GraphLearner$new(graph_rf)
learners_rf 's predict_type is [response], prob
GraphLearner:classif.ranger.threshold
- Model: list
- Parameters: classif.ranger.importance=impurity, classif.ranger.max.depth=4, classif.ranger.min.node.size=30, classif.ranger.mtry=4, classif.ranger.num.threads=1, classif.ranger.num.trees=400, threshold.thresholds=0.4444
- Packages: mlr3, mlr3pipelines, mlr3learners, ranger
- Predict Types: [response], prob
- Feature Types: logical, integer, numeric, character, factor, ordered, POSIXct
- Properties: featureless, hotstart_backward, hotstart_forward, importance, loglik, missings, multiclass, oob_error, selected_features, twoclass, weights
But when I use conterfacutal packages, it went wrong:
predictor1=Predictor$new(learners_rf,data=dat1,y="Prostate_cancer",type="prob") Warning: Output seems to be class instead of probabilities. Automatically transformed to 0 and 1 probabilities. You might want to set predict.type = 'prob' for Learner!
So my results are strange.How to solve it?
The counterfactuals package needs a model that outputs probabilities. Although you set the classif.ranger's predict.type to prob, you are using the po("threshold") PipeOp. The latter turns probability predictions into response predictions by thresholding them.
What is the reason why you are using thresholding? If you are using the counterfactuals package and want to limit yourself to counterfactuals that are beyond a certain probability, you probably need to use the desired_prob argument of the $find_counterfactuals() method.
And please don't cross-post on stackoverflow and here.
Closing this in favour of https://github.com/mlr-org/mlr3pipelines/issues/645