pbiecek / ceterisParibus

Ceteris Paribus Plots (What-If plots) for explanations of a single observation
https://pbiecek.github.io/ceterisParibus/
41 stars 13 forks source link

fix predict_function in ceteris_paribus #2

Closed agosiewska closed 6 years ago

agosiewska commented 6 years ago

I've fixed the problem for ceteris_paribus() with custom predict_function. It was working only when the name of the second parameter of predict_function was 'newdata'.

Code below was returning an error: Error in predict_function(model, newdata = new_data) : unused argument (newdata = new_data)

library(gbm)
library(DALEX)
library(ceterisParibus)

pred_boost<-function(model, data){
  predict(model, newdata=data, n.trees=model$n.trees)
}

gbm <- gbm(m2.price~., data = apartments, n.trees = 2000)
exp_gbm <- explain(gbm, data = apartmentsTest, y = apartmentsTest, predict_function = pred_boost)
cp_gbm <- ceteris_paribus(exp_gbm, observation = apartmentsTest[1,])
pbiecek commented 6 years ago

Thanks!