- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
石灰来源:https://github.com/marcotcr/lime
树解释器来源:tree interpreter
我试图了解 DecisionTree
如何使用 Lime 和 treeinterpreter 进行预测。虽然两者都声称他们能够在他们的描述中解释决策树。似乎两者都以不同的方式解释相同的 DecisionTree
。即特征贡献order。这怎么可能?如果两者都在看同一件事,并试图描述同一事件,但按不同顺序分配重要性。
我们应该信任谁?尤其是最重要的特征在预测中很重要的地方。
树的代码
import sklearn
import sklearn.datasets
import sklearn.ensemble
import numpy as np
import lime
import lime.lime_tabular
from __future__ import print_function
np.random.seed(1)
from treeinterpreter import treeinterpreter as ti
from sklearn.tree import DecisionTreeClassifier
iris = sklearn.datasets.load_iris()
dt = DecisionTreeClassifier(random_state=42)
dt.fit(iris.data, iris.target)
n = 100
instances =iris.data[n].reshape(1,-1)
prediction, biases, contributions = ti.predict(dt, instances)
for i in range(len(instances)):
print ("prediction:",prediction)
print ("-"*20)
print ("Feature contributions:")
print ("-"*20)
for c, feature in sorted(zip(contributions[i],
iris.feature_names),
key=lambda x: ~abs(x[0].any())):
print (feature, c)
石灰的代码
import sklearn
import sklearn.datasets
import sklearn.ensemble
import numpy as np
import lime
import lime.lime_tabular
from __future__ import print_function
np.random.seed(1)
from sklearn.tree import DecisionTreeClassifier
iris = sklearn.datasets.load_iris()
dt = DecisionTreeClassifier(random_state=42)
dt.fit(iris.data, iris.target)
explainer = lime.lime_tabular.LimeTabularExplainer(iris.data, feature_names=iris.feature_names,
class_names=iris.target_names,
discretize_continuous=False)
n = 100
exp = explainer.explain_instance(iris.data[n], dt.predict_proba, num_features=4, top_labels=2)
exp.show_in_notebook(show_table=True, predict_proba= True , show_predicted_value = True , show_all=False)
让我们先看看树的输出。
所以 a 它确实正确地说它是 virginica。但是,通过在
中分配重要性1) 花瓣宽度 (cm) 然后花瓣长度 (cm)
现在让我们看看 lime
的输出是的,它确实说算法预测了 virginica,但是看看它是如何进行分类的,我们清楚地看到以下内容
1)花瓣长度(cm)>花瓣宽度(cm)以石灰代替花瓣长度(cm)<花瓣宽度(cm)如图所示
2) 其中萼片宽度和萼片长度预测为零,石灰声称具有一定的值(value),如上传的图片所示
这里发生了什么?
当特征达到 1000+ 时,问题就越来越大,每个数字都对做出决定很重要。
最佳答案
Lime:对其工作原理的简短说明,摘自他们的github page :
Intuitively, an explanation is a local linear approximation of the model's behaviour. While the model may be very complex globally, it is easier to approximate it around the vicinity of a particular instance. While treating the model as a black box, we perturb the instance we want to explain and learn a sparse linear model around it, as an explanation. The figure below illustrates the intuition for this procedure. The model's decision function is represented by the blue/pink background, and is clearly nonlinear. The bright red cross is the instance being explained (let's call it X). We sample instances around X, and weight them according to their proximity to X (weight here is indicated by size). We then learn a linear model (dashed line) that approximates the model well in the vicinity of X, but not necessarily globally.
在 github 页面上的各个链接中有更详细的信息。
treeinterpreter:http://blog.datadive.net/interpreting-random-forests/ 上提供了有关其工作原理的说明(这是用于回归;可以找到一个非常相似的分类示例,可以找到 here)。
简而言之:假设我们有一个比较特征的节点 F
到某个值并基于此拆分实例。假设到达该节点的所有实例中有 50% 属于类 C
.假设我们有一个新实例,它最终被分配给该节点的左子节点,现在所有实例的 80% 属于类 C
.然后,特征的贡献F
因为这个决定被计算为 0.8 - 0.5 = 0.3
(如果沿叶路径有更多节点也使用特征 F
,则加上附加条款。
比较:需要注意的重要一点是,Lime 是一种独立于模型的方法(并非特定于决策树/RFs),它基于局部线性逼近。另一方面,Treeinterpreter 具体以与决策树本身类似的方式运行,并真正查看算法在比较中实际使用了哪些特征。所以他们实际上在做完全不同的事情。 Lime 说“一个特征很重要,如果我们稍微调整一下它就会产生不同的预测”。 Treeinterpreter 说“如果将某个特征与我们的一个节点中的阈值进行比较,它就会很重要,这会导致我们进行拆分,从而彻底改变了我们的预测”。
这很难明确回答。它们可能都以自己的方式有用。直觉上,你可能第一眼就倾向于 treeinterpreter,因为它是专门为决策树创建的。但是,请考虑以下示例:
F <= 50
, 向左走,否则向右走。如果大多数实例向左移动,只有一些向右移动,则这种设置是可能的。现在假设我们有一个带有 F = 49
的实例被分配到左侧并最终分配到第 1 类。Treeinterpreter 不会关心 F
真的很接近在根节点中等式的另一边结束,并且只分配了 0.48 - 0.50 = -0.02
的低贡献. Lime 会注意到 F
的变化只需一点点就会完全改变赔率。
哪一个是对的?这还不是很清楚。你可以说F
非常重要,因为如果它只有一点点不同,预测就会不同(然后石灰获胜)。你也可以争辩说F
对我们的最终预测没有贡献,因为在检查了它的值(value)之后我们几乎没有接近一个决定,并且之后仍然需要研究许多其他特征。然后 treeinterpreter 获胜。
为了在此处获得更好的想法,实际绘制学习到的决策树本身也可能会有所帮助。然后,您可以手动遵循它的决策路径,并决定您认为哪些功能很重要和/或看看您是否可以理解为什么 Lime 和 treeinterpreter 会说他们所说的。
关于python - Lime vs TreeInterpreter 用于解释决策树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48909418/
我在为 MacOSX 构建的独立包中添加 DMG 背景的自定义图标时遇到问题。我在项目的根目录中添加了一个包。正在从中加载自定义图标,但没有加载 DMG 背景图标。我正在使用 Java fx 2.2.
Qt for Symbian 和 Qt for MeeGo 有什么区别?我知道 Qt 是一个交叉编译平台。这是否意味着如果我使用来自 Qt 的库,完全相同的库可以在所有支持 Qt 的设备(例如 Sym
我正在尝试使用 C# .NET 3.5/4.0 务实地运行 SQL Server 数据库的备份。我已经找到了如何完成此操作,但是我似乎找不到用于备份的命名空间库。 我正在寻找 Microsoft.Sq
我最近在疯狂学习 Java,但我通常是一名 .NET 开发人员。 (所以请原谅我的新手问题。) 在 .Net 中,我可以在不使用 IIS 的情况下开发 ASP.Net 页面,因为它有一个简化的 Web
这post仅当打印命令中有字符串时才有用。现在我有大量的源代码,其中包含一条声明,例如 print milk,butter 应该格式化为 print(milk,butter) 用\n 捕获行尾并不成功
所以我的问题是: https://gist.github.com/panSarin/4a221a0923927115584a 当我保存这个表格时,我收到了标题中的错误 NoMethodError (u
如何让 Html5 音频在点击时播放声音? (ogg 用于 Firefox 等浏览器,mp3 用于 chrome 等浏览器) 到目前为止,我可以通过 onclick 更改为单个文件类型,但我无法像在普
如果it1和it2有什么区别? std::set s; auto it1 = std::inserter(s, s.begin()); auto it2 = std::inserter(s, s.en
4.0.0 com.amkit myapp SpringMVCFirst
我目前使用 Eclipse 作为其他语言的 IDE,而且我习惯于不必离开 IDE 做任何事情 - 但是我真的很难为纯 ECMAScript-262 找到相同或类似的设置。 澄清一下,我不是在寻找 DO
我想将带有字符串数组的C# 结构发送到C++ 函数,该函数接受void * 作为c# 结构和char** 作为c# 结构字符串数组成员。 我能够将结构发送到 c++ 函数,但问题是,无法从 c++ 函
我正在使用动态创建的链接: 我想为f:param附加自定义转换器,以从#{name}等中删除空格。 但是f:param中没有转换器
是否可以利用Redis为.NET创建后写或直写式缓存?理想情况下,透明的高速缓存是由单个进程写入的,并且支持从数据库加载丢失的数据,并每隔一段时间持久保存脏块? 我已经搜查了好几个小时,也许是goog
我正在通过bash执行命令的ssh脚本。 FILENAMES=( "export_production_20200604.tgz" "export_production_log_2020060
我需要一个正则表达式来出现 0 到 7 个字母或 0 到 7 个数字。 例如:匹配:1234、asdbs 不匹配:123456789、absbsafsfsf、asf12 我尝试了([a-zA-Z]{0
我有一个用于会计期间的表格,该表格具有期间结束和开始的开始日期和结束日期。我使用此表来确定何时发生服务交易以及何时在查询中收集收入,例如... SELECT p.PeriodID, p.FiscalY
我很难为只接受字符或数字的 Laravel 构建正则表达式验证。它是这样的: 你好<-好的 123 <- 好的 你好123 <-不行 我现在的正则表达式是这样的:[A-Za-z]|[0-9]。 reg
您实际上会在 Repeater 上使用 OnItemDataBound 做什么? 最佳答案 “此事件为您提供在客户端显示数据项之前访问数据项的最后机会。引发此事件后,数据项将被清空,不再可用。” ~
我有一个 fragment 工作正常的项目,我正在使用 jeremyfeinstein 的 actionbarsherlock 和滑动菜单, 一切正常,但是当我想自定义左侧抽屉列表单元格时,出现异常
最近几天,我似乎平均分配时间在构建我的第一个应用程序和在这里发布问题!! 这是我的第一个应用程序,也是我们的设计师完成的第一个应用程序。我试图满足他所做的事情的外观和感觉,但我认为他没有做适当的事情。
我是一名优秀的程序员,十分优秀!