Skip to content

Commit 8149e83

Browse files
authored
Merge pull request #1 from mini-pw/main
compare
2 parents 7a44c67 + 5f77ff2 commit 8149e83

32 files changed

+63935
-0
lines changed

Materialy/Lab4/LIME.R

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
### Model ###
2+
3+
data(titanic_imputed, package = "DALEX")
4+
5+
model <- ranger::ranger(survived~., data = titanic_imputed, classification = TRUE, probability = TRUE)
6+
7+
8+
###DALEXtra###
9+
10+
library(DALEX)
11+
library(DALEXtra)
12+
13+
explainer <- explain(model = model,
14+
data = titanic_imputed[,-8],
15+
y = titanic_imputed$survived)
16+
17+
18+
library(mlr)
19+
titanic_imputed_fct <- titanic_imputed
20+
titanic_imputed_fct$survived <- as.factor(titanic_imputed_fct$survived)
21+
22+
classif_task <- makeClassifTask(data = titanic_imputed_fct, target = "survived")
23+
classif_lrn <- makeLearner("classif.svm", predict.type = "prob")
24+
model_mlr <- train(classif_lrn, classif_task)
25+
26+
explainer_mlr <- explain(model = model_mlr,
27+
data = titanic_imputed_fct[,-8],
28+
y = as.numeric(as.character(titanic_imputed_fct$survived)))
29+
30+
### LIME ###
31+
32+
library("lime")
33+
model_type.dalex_explainer <- DALEXtra::model_type.dalex_explainer
34+
predict_model.dalex_explainer <- DALEXtra::predict_model.dalex_explainer
35+
36+
lime_johnny_mlr <- predict_surrogate(explainer = explainer_mlr,
37+
new_observation = titanic_imputed_fct[11, -8],
38+
n_features = 3,
39+
n_permutations = 1000,
40+
type = "lime")
41+
42+
lime_johnny_ranger <- predict_surrogate(explainer = explainer,
43+
new_observation = titanic_imputed_fct[11, -8],
44+
n_features = 3,
45+
n_permutations = 1000,
46+
type = "lime")
47+
48+
plot(lime_johnny)
49+
plot(lime_johnny_ranger)
50+
51+
### Break Down ###
52+
53+
pp_ranger_bd_1 <- predict_parts(explainer, new_observation = titanic_imputed[11,])
54+
plot(pp_ranger_bd_1)
55+
56+
pp_ranger_bd_2 <- predict_parts(explainer_mlr, new_observation = titanic_imputed[11,])
57+
plot(pp_ranger_bd_2)
58+
59+
60+
61+
# Zadanko
62+
63+
# Wez dowolny zbior, stworz dowolny model. Wygeneruj oraz porównaj wyjasnienie LIME oraz BreakDown
64+

Materialy/Lab4/lime_nb.ipynb

+321
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)