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

Error with single_prediction function: Error in UseMethod("broken") #4

Closed
kransom14 opened this issue Feb 20, 2018 · 9 comments
Closed

Comments

@kransom14
Copy link

When I try to run the vignette examples for the single_prediction() function I see the following error for the random forest model:

Error in UseMethod("broken") :
no applicable method for 'broken' applied to an object of class "c('randomForest.formula', 'randomForest')"

I have DALEX package version 0.1 and breakDown 0.1.3

@pbiecek
Copy link
Member

pbiecek commented Feb 21, 2018

Try breakDown 1.4 from github
https://github.com/pbiecek/breakDown
Version 1.3 supports only lm and glm model while 1.4 is model agnostic

@kransom14
Copy link
Author

kransom14 commented Feb 21, 2018 via email

@pbiecek
Copy link
Member

pbiecek commented Feb 21, 2018

Would you provide the full example for gbm? Will be easier to debug

@pbiecek
Copy link
Member

pbiecek commented Feb 21, 2018

Ok, I guess that your new observation is neither a data.frame nor matrix?

@kransom14
Copy link
Author

kransom14 commented Feb 21, 2018 via email

@pbiecek
Copy link
Member

pbiecek commented Feb 21, 2018

n.trees argument is required by predict.gbm but was not correctly passed from DALEX to breakDown.
Please update both packages and following example is working for me

library(gbm)
library(DALEX)
library(breakDown)

# create a gbm model
model <- gbm(quality ~ pH + residual.sugar + sulphates + alcohol, data = wine,
             distribution = "gaussian",
             n.trees = 1000,
             interaction.depth = 4,
             shrinkage = 0.01,
             n.minobsinnode = 10,
             verbose = FALSE)

# make an explainer for the model
explainer_gbm <- explain(model, data = wine)

# create a new observation
new.wine <- data.frame(citric.acid = 0.35,
                       sulphates = 0.6,
                       alcohol = 12.5,
                       pH = 3.36,
                       residual.sugar = 4.8)

exp_sgn <- single_prediction(explainer_gbm, observation = new.wine, n.trees = 1000)

exp_sgn
plot(exp_sgn)

@kransom14
Copy link
Author

This fixes it, thank you. I will close the issue.

@thormic
Copy link

thormic commented May 21, 2020

If anyone still had troubles with the first error (even after updating breakDown) - check if you are using explain from DALEX or from dplyr. If the latter is the case, just use DALEX::explain.

@bkochanski
Copy link

If anyone still had troubles with the first error (even after updating breakDown) - check if you are using explain from DALEX or from dplyr. If the latter is the case, just use DALEX::explain.

Thanks! Now I know what caused Błąd w poleceniu 'UseMethod("explain")': niestosowalna metoda dla 'explain' zastosowana do obiektu klasy "c('glm', 'lm')" ;-)

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

No branches or pull requests

4 participants