plot
Plot results of local interpretable model-agnostic explanations (LIME)
句法
Description
visualizes the LIME results in theF
=图(结果
)lime
目的结果
。这Function returns the数字
目的F
。UseF
to query or modify数字Properties创建它之后的图。
这个数字包含了地平线tal bar graph that shows the coefficient values of a linear simple model or predictor importance values of a decision tree simple model, depending on the simple model in
结果
((SimpleModel
property of结果
)。该图分别显示了使用机器学习模型和简单模型计算的查询点的两个预测。这些值对应于
BlackboxFitted
财产和简单地解码
property of结果
。
Examples
用决策树简单模型解释预测
培训分类模型并创建一个lime
使用决策树简单模型的对象。当您创建一个lime
对象,指定查询点和重要的预测指标的数量,以便软件生成合成数据集的样本,并拟合具有重要预测指标的查询点的简单模型。然后通过使用对象函数在简单模型中显示估计的预测变量plot
。
Load theCreditRating_Historical
数据集。数据集包含客户ID及其财务比率,行业标签和信用评级。
资源描述= readtable('Creditrating_historical.dat');
Display the first three rows of the table.
头(TBL,3)
ans=3×8 tableID WC_TA RE_TA EBIT_TA MVE_BVTD S_TA Industry Rating _____ _____ _____ _______ ________ _____ ________ ______ 62394 0.013 0.104 0.036 0.447 0.142 3 {'BB'} 48608 0.232 0.335 0.062 1.969 0.281 8 {'A' } 42444 0.311 0.367 0.074 1.935 0.366 1 {'A' }
创建一个table of predictor variables by removing the columns of customer IDs and ratings from资源描述
。
tblx = removevars(tbl,["ID",,,,“评分”);
Train a blackbox model of credit ratings by using the合身cecoc
功能。
blackbox = fitcecoc(tblx,tbl。“分类预期”,,,,'行业');
创建一个lime
使用决策树简单模型解释了最后观察的预测对象。指定'NumImportantPredictors'
最多可以找到6个重要预测因子。如果指定“查询点”
and'NumImportantPredictors'
创建一个值lime
对象,然后该软件生成合成数据集的样本,并将简单的可解释模型拟合到合成数据集。
queryPoint = tblX(end,:)
queryPoint=1×6 tablewc_ta re_ta ebit_ta mve_bvtd s_ta行业_____ _____ ___________________________________________________________________ 0.463 0.065 0.065 2.924 0.34 2
rng('default')% For reproducibility结果= lime(blackbox,“查询点”,查询点,'NumImportantPredictors',,,,6,...'SimpleModelType',,,,'tree')
结果= lime with properties: BlackboxModel: [1x1 ClassificationECOC] DataLocality: 'global' CategoricalPredictors: 6 Type: 'classification' X: [3932x6 table] QueryPoint: [1x6 table] NumImportantPredictors: 6 NumSyntheticData: 5000 SyntheticData: [5000x6 table] Fitted: {5000x1 cell} SimpleModel: [1x1 ClassificationTree] ImportantPredictors: [2x1 double] BlackboxFitted: {'AA'} SimpleModelFitted: {'AA'}
Plot thelime
目的结果
通过使用对象函数plot
。To display an existing underscore in any predictor name, change theTickLabelInterpreter
value of the axes to'none'
。
f =图(结果);f.currentaxes.ticklabelinterpreter ='none';
这plot displays two predictions for the query point, which correspond to theBlackboxFitted财产和简单地解码property of结果
。
水平条形图显示了排序的预测指标值。lime
找到财务比率变量EBIT_TA
andWC_TA
as important predictors for the query point.
您可以使用数据提示或Bar Properties。For example, you can findBar
目的s by using theFindobj
Function and add labels to the ends of the bars by using thetext
功能。
b = findobj(f,'Type',,,,'bar');text(b.YEndPoints+0.001,b.XEndPoints,string(b.YData))
另外,您可以在表中显示带有预测变量名称的表中的系数值。
imp = b.ydata;flipud(array2table(imp',,...'Rownames',f.currentaxes.yticklabel,'variablenames',,,,{“预测重要性”})))
ans=2×1桌预测器重要性____________________ mve_bvtd 0.088412 re_ta 0.0018061
用线性简单模型解释预测
训练回归模型并创建一个lime
目的that uses a linear simple model. When you create alime
查询对象,如果不指定点和the number of important predictors, then the software generates samples of a synthetic data set but does not fit a simple model. Use the object function合身
to fit a simple model for a query point. Then display the coefficients of the fitted linear simple model by using the object functionplot
。
Load thecarbig
data set, which contains measurements of cars made in the 1970s and early 1980s.
loadcarbig
创建一个table containing the predictor variablesAcceleration
,,,,Cylinders
,,,,and so on, as well as the response variableMPG
。
tbl =表(加速度,圆柱体,位移,马力,模型_ Year,重量,MPG);
Removing missing values in a training set can help reduce memory consumption and speed up training for thefitrkernel
功能。Remove missing values in资源描述
。
资源描述= rmmissing(tbl);
通过从中删除响应变量来创建一个预测变量的表资源描述
。
TBLX= removevars(tbl,'mpg');
Train a blackbox model ofMPG
by using thefitrkernel
功能。
rng('default')% For reproducibilitymdl = fitrkernel(tblX,tbl.MPG,“分类预期”,[2 5]);
创建一个lime
目的。指定a predictor data set becausemdl
不包含预测数据。
结果=石灰(MDL,TBLX)
results = lime with properties: BlackboxModel: [1x1 RegressionKernel] DataLocality: 'global' CategoricalPredictors: [2 5] Type: 'regression' X: [392x6 table] QueryPoint: [] NumImportantPredictors: [] NumSyntheticData: 5000 SyntheticData: [5000x6 table]拟合:[5000x1 double] simpleModel:[]重要predictors:[] blackboxfittit:[] simplememodelfitting:[]
结果
包含生成的合成数据集。这SimpleModel
属性为空([]
)。
Fit a linear simple model for the first observation inTBLX
。指定the number of important predictors to find as 3.
queryPoint = tblX(1,:)
queryPoint=1×6 tableAcceleration Cylinders Displacement Horsepower Model_Year Weight ____________ _________ ____________ __________ __________ ______ 12 8 307 130 70 3504
结果= fit(results,queryPoint,3);
Plot thelime
目的结果
通过使用对象函数plot
。To display an existing underscore in any predictor name, change theTickLabelInterpreter
value of the axes to'none'
。
f =图(结果);f.currentaxes.ticklabelinterpreter ='none';
这plot displays two predictions for the query point, which correspond to theBlackboxFitted财产和简单地解码property of结果
。
这horizontal bar graph shows the coefficient values of the simple model, sorted by their absolute values. LIME findsHorsepower
,,,,Model_Year
,,,,andCylinders
as important predictors for the query point.
Model_Year
andCylinders
are categorical predictors that have multiple categories. For a linear simple model, the software creates one less dummy variable than the number of categories for each categorical predictor. The bar graph displays only the most important dummy variable. You can check the coefficients of the other dummy variables using theSimpleModel
property of结果
。显示排序的系数值,包括所有分类虚拟变量。
[~,I] = sort(abs(results.SimpleModel.Beta),'descend');table(results.SimpleModel.ExpandedPredictorNames(I)',results.SimpleModel.Beta(I),...'variablenames',,,,{'Exteded Predictor Name',,,,'系数'})
ans=17×2 tableExteded Predictor Name Coefficient __________________________ ___________ {'Horsepower' } -3.4485e-05 {'Model_Year (74 vs. 70)'} -6.1279e-07 {'Model_Year (80 vs. 70)'} -4.015e-07 {'model_year(81 vs. 70)'} 3.4176E-07 {'model_year(82 vs. 70)'} -2.2483e-07 {'canlinders(6 vs. 8)'} -1.9024e-07-vs. 70)'} 1.8136E-07 {'cALINDERS(5 vs. 8)'} 1.7461E-07 {'model_year(71 vs. 70)'} 1.558e-07 {'model_year(75 vs. 70)''} 1.5456E-07 {'model_year(77 vs. 70)'} 1.521E-07 {'model_year(78 vs. 70)'} 1.4272E-07 {'model_year(72 vs. 70){'model_year(73 vs. 70)'} 4.7214E-08 {'cALINDERS(4 vs. 8)'} 4.5118e-08 {'model_year(79 vs. 70)'} -2.2598e-08e-08e-08⋮
Input Arguments
结果
-石灰结果
lime
目的
石灰结果,,,,specified as alime
目的。这SimpleModel
property of结果
must contain a fitted simple model.
References
[1] Ribeiro,Marco Tulio,S。Singh和C. Guestrin。“'我为什么要信任你?':解释任何分类器的预测。”In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining,,,,1135–44. San Francisco, California: ACM, 2016.
版本历史记录
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
选择一个网站以获取可用的翻译内容,并查看本地事件和优惠。根据您的位置,我们建议您选择:。
You can also select a web site from the following list:
如何获得最佳网站性能
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
Americas
- América Latina((Español)
- Canada((English)
- United States((English)