如何从scikit-learn解释决策树 [英] how to explain the decision tree from scikit-learn

查看:104
本文介绍了如何从scikit-learn解释决策树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从scikit-learn了解决策树的结果时,我遇到两个问题.例如,这是我的决策树之一:

I have two problems with understanding the result of decision tree from scikit-learn. For example, this is one of my decision trees:

我的问题是我如何使用树?

My question is that how I can use the tree?

第一个问题是:如果样本满足条件,则转到 LEFT 分支(如果存在),否则转到 RIGHT .就我而言,如果样本的X [7]> 63521.3984.然后样品将进入绿色框.正确吗?

The first question is that: if a sample satisfied the condition, then it goes to the LEFT branch (if exists), otherwise it goes RIGHT. In my case, if a sample with X[7] > 63521.3984. Then the sample will go to the green box. Correct?

第二个问题是:当样本到达叶节点时,我怎么知道它属于哪个类别?在此示例中,我要分类三个类别.在红色框中,分别有91个,212个和113个满足条件的样本.但是,如何确定类别? 我知道有一个功能 clf.predict(sample)可以告诉类别.我可以从图中做到这一点吗??? 非常感谢.

The second question is that: when a sample reaches the leaf node, how can I know which category it belongs? In this example, I have three categories to classify. In the red box, there are 91, 212, and 113 samples are satisfied the condition, respectively. But how can I decide the category? I know there is a function clf.predict(sample) to tell the category. Can I do that from the graph??? Many thanks.

推荐答案

每个框中的value行按顺序告诉您该节点上有多少个样本属于每个类别.这就是为什么在每个框中,value中的数字加到sample中显示的数字的原因.例如,在您的红色框中,91 + 212 + 113 = 416.因此,这意味着如果到达此节点,则类别1中有91个数据点,类别2中有212个数据点,类别3中有113个数据点.

The value line in each box is telling you how many samples at that node fall into each category, in order. That's why, in each box, the numbers in value add up to the number shown in sample. For instance, in your red box, 91+212+113=416. So this means if you reach this node, there were 91 data points in category 1, 212 in category 2, and 113 in category 3.

如果要预测到达决策树中该叶子的新数据点的结果,则将预测类别2,因为这是该节点上样本的最常见类别.

If you were going to predict the outcome for a new data point that reached that leaf in the decision tree, you would predict category 2, because that is the most common category for samples at that node.

这篇关于如何从scikit-learn解释决策树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆