决策树(Decision Trees)
创始人
2024-02-25 08:01:23
0

决策树(Decision Trees)

1. Training and Visualizing a Decision Tree

can perform both classification and regression tasks, and even multioutput tasks

tree_clf = DecisionTreeClassifier(max_depth=2)
export_graphviz(tree_clf,out_file=image_path("iris_tree.dot"),feature_names=iris.feature_names[2:],class_names=iris.target_names,rounded=True,filled=True
)
$ dot -Tpng iris_tree.dot -o iris_tree.png

2. Making Predictions

  • require very little data preparation.
  • don’t require feature scaling or centering at all
  • algorithm
    CART, binary trees
    ID3, mul-children trees
  • etimating class probabilities
    根据叶子节点的value,就可以输出每个分类的概率pkp_kpk​
  • gini 节点的纯洁程度,0最纯洁
    Ginii=1−∑k=1npi,k2Gini_i=1-\sum_{k=1}^{n}p_{i,k}^2 Ginii​=1−k=1∑n​pi,k2​
    pi,kp_{i,k}pi,k​表示第i个节点上,第k类出现的概率

3. The CART Training Algorithm

递归的为每个节点寻找最好的划分特征k和划分特征的阈值t,CART Cost Function For classification
J(k,tk)=mleftmGleft+mrightmGright(Gmeasurestheimpurityofthesubset)J(k, t_k)=\frac{m_{left}}{m}G_{left} + \frac{m_{right}}{m}G_{right} \;\; (G \; measures \; the \; impurity \; of \; the \; subset) J(k,tk​)=mmleft​​Gleft​+mmright​​Gright​(Gmeasurestheimpurityofthesubset)
处了GINI指数可以作为G,香农信息熵也是一种方法
Hi=−∑k=1,pi,k≠0npi,klog(pi,k)H_i=-\sum_{k=1,p_{i,k}\neq 0}^{n}p_{i,k}log(p_{i,k}) Hi​=−k=1,pi,k​​=0∑n​pi,k​log(pi,k​)
默认选择GINI指数,计算复杂度低一些,二者训练出来的树差不多,Gini impurity tends to isolate the most frequent class in its own branch of the tree, while entropy tends to produce slightly more balanced trees

  • CART 全称是 Classifcation And Regression Tree
  • CART is a greedy algorithm 贪心算法
    1. A greedy algorithm often produces a reasonably good solution,
    2. but it is not guaranteed to be the optimal solution.
    3. finding the optimal tree is known to be an NP-Complete problem
    4. it requires O(exp(m)) time
  • mathematical question
    1. P is the set of problems that can be solved in polynomial time
    2. NP is the set of problems whose solutions can be verified in polynomial time
    3. NP-Hard problem is a problem to which any NP problem can be reduced in polynomial time.
    4. An NP-Complete problem is both NP and NP-Hard

4. Regularization Hyperparameters

  • a nonparametric model
    the number of parameters is not determined prior to training
  • a few parameters restrict the shape of the Decision Tree
    1. min_samples_split
    2. min_samples_leaf
    3. min_weight_fraction_leaf, same as min_samples_leaf but expressed as a fraction of the total number of eighted instances
    4. max_leaf_nodes
    5. max_features, maximum number of features that are evaluated for splitting at each node
  • increasing min_* hyperparameters or reducing max_* hyperparameters will regularize the model
  • 另可以先不加任何约束训练一棵树,完成后再对树进行裁剪的方式正则化
  • The computational complexity of training a Decision Tree is O(n × m log(m))

5. Regression

将混乱程度修改为均值平方差

from sklearn.tree import DecisionTreeRegressor
# setting min_samples_leaf=10 to obviously overfitting
tree_reg = DecisionTreeRegressor(max_depth=2)
tree_reg.fit(X, y)

返回的value值,是这一个区间内的所有samples的平均值

6. Instability 不确定性

  • 优点 a lot going
    1. simple to understand and interpret
    2. easy to use
    3. versatile, and powerful
  • 缺点 a few limitations
    1. orthogonal decision boundaries 对非线性的样本不好处理
    2. very sensitive to small variations in the training data

@ 学必求其心得,业必贵其专精

相关内容

热门资讯

保存时出现了1个错误,导致这篇... 当保存文章时出现错误时,可以通过以下步骤解决问题:查看错误信息:查看错误提示信息可以帮助我们了解具体...
汇川伺服电机位置控制模式参数配... 1. 基本控制参数设置 1)设置位置控制模式   2)绝对值位置线性模...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
表格中数据未显示 当表格中的数据未显示时,可能是由于以下几个原因导致的:HTML代码问题:检查表格的HTML代码是否正...
本地主机上的图像未显示 问题描述:在本地主机上显示图像时,图像未能正常显示。解决方法:以下是一些可能的解决方法,具体取决于问...
表格列调整大小出现问题 问题描述:表格列调整大小出现问题,无法正常调整列宽。解决方法:检查表格的布局方式是否正确。确保表格使...
不一致的条件格式 要解决不一致的条件格式问题,可以按照以下步骤进行:确定条件格式的规则:首先,需要明确条件格式的规则是...
Android|无法访问或保存... 这个问题可能是由于权限设置不正确导致的。您需要在应用程序清单文件中添加以下代码来请求适当的权限:此外...
【NI Multisim 14...   目录 序言 一、工具栏 🍊1.“标准”工具栏 🍊 2.视图工具...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...