Skip to content

Commit

Permalink
Merge pull request #4 from mini-pw/main
Browse files Browse the repository at this point in the history
lab 4
  • Loading branch information
jakubjung authored Apr 7, 2021
2 parents 8c9f2a8 + 5f77ff2 commit 94e376f
Show file tree
Hide file tree
Showing 7 changed files with 22,184 additions and 0 deletions.
64 changes: 64 additions & 0 deletions Materialy/Lab4/LIME.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
### Model ###

data(titanic_imputed, package = "DALEX")

model <- ranger::ranger(survived~., data = titanic_imputed, classification = TRUE, probability = TRUE)


###DALEXtra###

library(DALEX)
library(DALEXtra)

explainer <- explain(model = model,
data = titanic_imputed[,-8],
y = titanic_imputed$survived)


library(mlr)
titanic_imputed_fct <- titanic_imputed
titanic_imputed_fct$survived <- as.factor(titanic_imputed_fct$survived)

classif_task <- makeClassifTask(data = titanic_imputed_fct, target = "survived")
classif_lrn <- makeLearner("classif.svm", predict.type = "prob")
model_mlr <- train(classif_lrn, classif_task)

explainer_mlr <- explain(model = model_mlr,
data = titanic_imputed_fct[,-8],
y = as.numeric(as.character(titanic_imputed_fct$survived)))

### LIME ###

library("lime")
model_type.dalex_explainer <- DALEXtra::model_type.dalex_explainer
predict_model.dalex_explainer <- DALEXtra::predict_model.dalex_explainer

lime_johnny_mlr <- predict_surrogate(explainer = explainer_mlr,
new_observation = titanic_imputed_fct[11, -8],
n_features = 3,
n_permutations = 1000,
type = "lime")

lime_johnny_ranger <- predict_surrogate(explainer = explainer,
new_observation = titanic_imputed_fct[11, -8],
n_features = 3,
n_permutations = 1000,
type = "lime")

plot(lime_johnny)
plot(lime_johnny_ranger)

### Break Down ###

pp_ranger_bd_1 <- predict_parts(explainer, new_observation = titanic_imputed[11,])
plot(pp_ranger_bd_1)

pp_ranger_bd_2 <- predict_parts(explainer_mlr, new_observation = titanic_imputed[11,])
plot(pp_ranger_bd_2)



# Zadanko

# Wez dowolny zbior, stworz dowolny model. Wygeneruj oraz porównaj wyjasnienie LIME oraz BreakDown

321 changes: 321 additions & 0 deletions Materialy/Lab4/lime_nb.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 94e376f

Please sign in to comment.