建筑工程东莞网站建设,用wordpress插件推荐,嘉兴免费做网站,网站所有页面只显示域名本篇主要介绍几种其他较常用的模型解释性方法。
1. Permutation Feature Importance(PFI)
1.1 算法原理 置换特征重要性(Permutation Feature Importance)的概念很简单#xff0c;其衡量特征重要性的方法如下#xff1a;计算特征改变后模型预测误差的增加。如果打乱该特征的… 本篇主要介绍几种其他较常用的模型解释性方法。
1. Permutation Feature Importance(PFI)
1.1 算法原理 置换特征重要性(Permutation Feature Importance)的概念很简单其衡量特征重要性的方法如下计算特征改变后模型预测误差的增加。如果打乱该特征的值增加了模型的误差那么一个特征就是重要的如果打乱之后模型误差不变那就认为该特征不重要。
1.2 Python实现 使用Wine酒数据来训练模型。其模型训练代码如下
import pandas as pd
import numpy as np
from sklearn.datasets import load_wine
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
from matplotlib import pyplot as plt
import seaborn as snswineload_wine()
Xpd.DataFrame(wine.data,columnswine.feature_names)
ywine.targetrfcRandomForestClassifier(max_depth4,random_state0)
rfc.fit(X,y)
y_predrfc.predict(X)accuracyaccuracy_score(y,y_pred)1.2.1 sklearn包实现 ems;常用的机器学习包sklearn中也集成了这种方法但是需要单独写代码来实现可视化。其具体代码如下
from sklearn.inspection import permutation_importance
resultpermutation_importance(rfc,X,y,n_repeats10,random_state42)featpd.DataFrame(np.hstack(([[col] for col in wine.feature_names],[[item] for item in result[importances_mean]])),columns[Feat,Imp])
feat[Imp]feat[Imp].astype(float)
featfeat.sort_values(Imp,ascendingFalse)
sns.barplot(xImp,yFeat,datafeat)
plt.show()其结果如下
1.2.2 eli5包实现
import eli5
from eli5.sklearn import PermutationImportance
permPermutationImportance(rfc,n_iter10)
perm.fit(X,y)
eli5.show_weights(perm,feature_nameswine.feature_names)其结果如下
1.3 参考资料
https://blog.csdn.net/weixin_39653948/article/details/110731460https://blog.csdn.net/qq_41185868/article/details/126046956
2 Partial Dependency Plots(部分依赖图,PDP)
2.1 算法原理 部分依赖图(PDP)展示了一个或两个特征对机器学习模型预测结果的边际效应。部分依赖图可以显示目标和特征之间的关系是线性的、单调的还是更复杂的关系。PDP假设所有特征两两不相关。其具体步骤如下
训练一个机器学习模型(假设特征依次为F1…Fn,yF_{1} \dots F_{n},yF1…Fn,y为目标变量);假设需要探究特征F1F_{1}F1对目标变量yyy的边际效应;特征F1F_{1}F1的取值依次为(a1,a2,…,an)(a_{1},a_{2},\dots,a_{n})(a1,a2,…,an); 依次用a1,a2,…,ana_{1},a_{2},\dots,a_{n}a1,a2,…,an代替F1F_{1}F1列其他特征保持不变。利用训练好的模型对这些数据进行预测计算所有样本的预测平均值。以特征F1F_{1}F1的不同取值为X轴其对应的预测样本平均值为Y轴进行作图即可。
2.2 Python实现
2.2.1 安装PDPbox包 使用如下代码直接安装PDPbox包的时候经常报错。报错的原因在于matplotlib V3.1.1无法正确安装。
pip install PDPbox在网上查了很多资料也没有解决所以在相关网站https://pypi.tuna.tsinghua.edu.cn/simple/pdpbox/ 直接下载了pdpbox的压缩包解压之后将以下两个文件直接放到python安装路径的lib/site-packages文件夹下即可。
2.2.2 PDPbox实现
单变量的边际效用
from pdpbox import pdppdp_goalspdp.pdp_isolate(modelrfc,datasetX,model_featureswine.feature_names,featurewine.feature_names[0])
pdp.pdp_plot(pdp_goals,wine.feature_names[0])
plt.show()交叉特征的边际效用
pdp_goalspdp.pdp_interact(modelrfc,datasetX,model_featureswine.feature_names,featureswine.feature_names[3:5])
pdp.pdp_interact_plot(pdp_goals,feature_nameswine.feature_names[3:5])
plt.show()2.2.3 sklearn实现 除了使用专用的PDPbox箱之外还可以使用sklearn包来实现部分依赖图。具体使用方法如下
from sklearn.inspection import plot_partial_dependence
plot_partial_dependence(rfc,X,featureswine.feature_names[0:1],feature_nameswine.feature_names,target0)
plt.show()plot_partial_dependence(rfc,X,featureswine.feature_names[3:5],feature_nameswine.feature_names,target0)
plt.show()其结果如下(这里仅显示第二组结果)
3 Individual Conditional Expectation(ICE)
3.1 算法原理 个体条件期望计算方法与PDP类似它刻画的是每个个体的预测值与单一变量之间的关系消除了非均匀效应的影响。
3.2 参考资料
https://blog.csdn.net/sinat_26917383/article/details/115669705 文章转载自: http://www.morning.zrlwl.cn.gov.cn.zrlwl.cn http://www.morning.fgwzl.cn.gov.cn.fgwzl.cn http://www.morning.lndongguan.com.gov.cn.lndongguan.com http://www.morning.xflzm.cn.gov.cn.xflzm.cn http://www.morning.rgxll.cn.gov.cn.rgxll.cn http://www.morning.wgrm.cn.gov.cn.wgrm.cn http://www.morning.bmpjp.cn.gov.cn.bmpjp.cn http://www.morning.bxdlrcz.cn.gov.cn.bxdlrcz.cn http://www.morning.lrnfn.cn.gov.cn.lrnfn.cn http://www.morning.cpnlq.cn.gov.cn.cpnlq.cn http://www.morning.xnltz.cn.gov.cn.xnltz.cn http://www.morning.nkyqh.cn.gov.cn.nkyqh.cn http://www.morning.xlwpz.cn.gov.cn.xlwpz.cn http://www.morning.tnbas.com.gov.cn.tnbas.com http://www.morning.lnbcx.cn.gov.cn.lnbcx.cn http://www.morning.tygn.cn.gov.cn.tygn.cn http://www.morning.xyyplp.cn.gov.cn.xyyplp.cn http://www.morning.lkfsk.cn.gov.cn.lkfsk.cn http://www.morning.jzykq.cn.gov.cn.jzykq.cn http://www.morning.yqhdy.cn.gov.cn.yqhdy.cn http://www.morning.xxwfq.cn.gov.cn.xxwfq.cn http://www.morning.spkw.cn.gov.cn.spkw.cn http://www.morning.xlpdm.cn.gov.cn.xlpdm.cn http://www.morning.nclbk.cn.gov.cn.nclbk.cn http://www.morning.fqnql.cn.gov.cn.fqnql.cn http://www.morning.nbhft.cn.gov.cn.nbhft.cn http://www.morning.kngqd.cn.gov.cn.kngqd.cn http://www.morning.ymhjb.cn.gov.cn.ymhjb.cn http://www.morning.hmjasw.com.gov.cn.hmjasw.com http://www.morning.sfphz.cn.gov.cn.sfphz.cn http://www.morning.rjrh.cn.gov.cn.rjrh.cn http://www.morning.jfwbr.cn.gov.cn.jfwbr.cn http://www.morning.qnxtz.cn.gov.cn.qnxtz.cn http://www.morning.srnhk.cn.gov.cn.srnhk.cn http://www.morning.tgtwy.cn.gov.cn.tgtwy.cn http://www.morning.xkgyh.cn.gov.cn.xkgyh.cn http://www.morning.kllzy.com.gov.cn.kllzy.com http://www.morning.yhxhq.cn.gov.cn.yhxhq.cn http://www.morning.xhhqd.cn.gov.cn.xhhqd.cn http://www.morning.mhpkz.cn.gov.cn.mhpkz.cn http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn http://www.morning.xirfr.cn.gov.cn.xirfr.cn http://www.morning.ai-wang.cn.gov.cn.ai-wang.cn http://www.morning.tpnx.cn.gov.cn.tpnx.cn http://www.morning.nsjpz.cn.gov.cn.nsjpz.cn http://www.morning.mkydt.cn.gov.cn.mkydt.cn http://www.morning.ndngj.cn.gov.cn.ndngj.cn http://www.morning.sqdjn.cn.gov.cn.sqdjn.cn http://www.morning.zpyh.cn.gov.cn.zpyh.cn http://www.morning.kpmxn.cn.gov.cn.kpmxn.cn http://www.morning.bqwnp.cn.gov.cn.bqwnp.cn http://www.morning.jgncd.cn.gov.cn.jgncd.cn http://www.morning.nqrlz.cn.gov.cn.nqrlz.cn http://www.morning.yqhdy.cn.gov.cn.yqhdy.cn http://www.morning.srckl.cn.gov.cn.srckl.cn http://www.morning.slqgl.cn.gov.cn.slqgl.cn http://www.morning.gjmbk.cn.gov.cn.gjmbk.cn http://www.morning.wtlyr.cn.gov.cn.wtlyr.cn http://www.morning.cwyrp.cn.gov.cn.cwyrp.cn http://www.morning.msmtf.cn.gov.cn.msmtf.cn http://www.morning.fjscr.cn.gov.cn.fjscr.cn http://www.morning.dtlqc.cn.gov.cn.dtlqc.cn http://www.morning.lzsxp.cn.gov.cn.lzsxp.cn http://www.morning.htpjl.cn.gov.cn.htpjl.cn http://www.morning.rdzgm.cn.gov.cn.rdzgm.cn http://www.morning.ndlww.cn.gov.cn.ndlww.cn http://www.morning.wqpb.cn.gov.cn.wqpb.cn http://www.morning.pndhh.cn.gov.cn.pndhh.cn http://www.morning.czqqy.cn.gov.cn.czqqy.cn http://www.morning.ejknty.cn.gov.cn.ejknty.cn http://www.morning.clnmf.cn.gov.cn.clnmf.cn http://www.morning.ypdhl.cn.gov.cn.ypdhl.cn http://www.morning.syznh.cn.gov.cn.syznh.cn http://www.morning.gychx.cn.gov.cn.gychx.cn http://www.morning.kpbn.cn.gov.cn.kpbn.cn http://www.morning.lthtp.cn.gov.cn.lthtp.cn http://www.morning.nnttr.cn.gov.cn.nnttr.cn http://www.morning.hcgbm.cn.gov.cn.hcgbm.cn http://www.morning.lhxdq.cn.gov.cn.lhxdq.cn http://www.morning.lqlfj.cn.gov.cn.lqlfj.cn