首页 > > > R语言可解释机器学习:iBreakDown简介
作者:黄天元,复旦大学博士在读,热爱数据科学与开源工具(R),致力于利用数据科学迅速积累行业经验优势和科学知识发现,涉猎内容包括但不限于信息计量、机器学习、数据可视化、应用统计建模、知识图谱等,著有《R语言数据高效处理指南》。知乎专栏:R语言数据挖掘。邮箱:huang.tian-yuan@qq.com.欢迎合作交流

DALEX包构筑的可解释机器学习已经有了很多更新,所以对相关的方法需要跟进。这是一个名为“DrWhy”的项目,希望能够利用各种方法对黑箱模型进行解析。总项目主页见:
https://github.com/ModelOriented/DrWhy今天来尝试一下其中的一个组成部分:iBreakDown(ModelOriented/iBreakDown)。它的主要任务是对于构建好的模型和一个新的实例,来探索不同变量对这个实例响应变量的贡献。
下面,我们对官方文档Explanations in natural language进行一个简要的演示和解析。这个数据的背景是经典的泰坦尼克号乘客生存概率预测。
# 加载包
library("DALEX")
library("iBreakDown")
library("randomForest")
# 清除缺失值
titanic <- na.omit(titanic)
# 构建随机森林模型
model_titanic_rf <- randomForest(survived == "yes" ~ .,
data = titanic
)
explain_titanic_rf <- explain(model_titanic_rf, # 构建的模型
data = titanic[,-9], # 去除响应变量的数据
y = titanic$survived == "yes", # 响应变量
label = "Random Forest") # 自定义取名为了让获得的结果跟文档一致,我们找到信息一样的乘客并记录下来放在passenger变量中。
library(tidyfst)
titanic %>% filter_dt(age == 26,gender == "male",country == "England",
class == "engineering crew",
embarked == "Southampton") %>%
distinct_dt() %>%
as.data.frame() -> passanger
passanger# 进行拆解
bd_rf <- break_down(explain_titanic_rf,
passanger,
keep_distributions = TRUE) # 保留数据分布
# 可视化
plot(bd_rf)

describe(bd_rf)
## 以下为输出:
Random Forest predicts, that the prediction for the selected instance is 0.159 which is lower than the average model prediction. For the selected instance model's prediction is lower, than for 65% of all observations.
The most important variable that decrease the prediction is gender.
Other variables are with less importance. The contribution of all other variables is -0.007. 结果表明,这名乘客预测出来的存活率为0.159,低于平均存活率。之所以这么低,最主要的因素是性别,其他因素相对不重要。
如果想获知分布的具体情况,可以把display_distribution_details参数设定为TRUE。
更多的用法,请参考:
https://modeloriented.github.io/iBreakDown/index.html原文作者:;如有侵权,请联系管理员删除。