1 데이터와 모형

데이터와 기계학습 예측모형을 준비하자. DALEX 팩키지에 포함된 타이타닉 데이터를 준비한다.

library(tidyverse)

data(titanic_imputed, package = "DALEX")

head(titanic_imputed)
  gender age class    embarked  fare sibsp parch survived
1   male  42   3rd Southampton  7.11     0     0        0
2   male  13   3rd Southampton 20.05     0     2        0
3   male  16   3rd Southampton 20.05     1     1        0
4 female  39   3rd Southampton 20.05     1     1        1
5 female  16   3rd Southampton  7.13     0     0        1
6   male  25   3rd Southampton  7.13     0     0        1

생존확률 예측 기계학습 모형을 Random Forest, GLM 두가지 종류로 개발하자.

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

titanic_glm <- glm(survived ~ ., 
                   data = titanic_imputed)

2 설명자(Explainer)

기계학습 모형을 설명자(Explainer) 객체로 변환시킨다.

library(modelDown)

explainer_rf <- DALEX::explain(titanic_rf,
                               data = titanic_imputed[, -8], 
                               y = titanic_imputed[, 8], 
                               verbose = FALSE)

explainer_rf
Model label:  ranger 
Model class:  ranger 
Data head  :
  gender age class    embarked  fare sibsp parch
1   male  42   3rd Southampton  7.11     0     0
2   male  13   3rd Southampton 20.05     0     2

3 XAI 보고서

data/modelDown_rf 폴더에 저장시킨다.

modelDown(explainer_rf, output_folder = "data/modelDown_rf")
[1] "Generating auditor..."
[1] "Generating model_performance..."
[1] "Generating variable_importance..."
[1] "Generating variable_response..."

4 XAI 보고서 불러오기

XAI 보고서를 클릭하면 XAI 보고서를 HTML 형태로 받아볼 수 있다.

htmltools::includeHTML("data/modelDown_rf/index.html")
 

데이터 과학자 이광춘 저작

kwangchun.lee.7@gmail.com