Classification week3: decision tree 笔记
华盛顿大学 machine learnign :classification week 3 笔记

第二步:

注:
其中 ,mistake 的计算方法:
给定一个节点的数据集M,对每个特征hi(x),根据特征hi(x)将节点的数据集M分类。
统计哪个类别占多数,记为多数类。
所有不在多数类里的数据都作为误判mistakes
classification error = (left_mistakes + right_mistakes) / num_data_points
第三步:建树
考虑到防止过拟合:

1. early stopping:
停止条件:

建树过程:
def decision_tree_create(data, features, target, current_depth = 0,
max_depth = 10, min_node_size=1,
min_error_reduction=0.0): remaining_features = features[:]
target_values = data[target] # Stopping condition 1: All nodes are of the same type.
if intermediate_node_num_mistakes(target_values) == 0:
return create_leaf(target_values) # Stopping condition 2: No more features to split on.
if remaining_features == []:
return create_leaf(target_values) # Early stopping condition 1: Reached max depth limit.
if current_depth >= max_depth:
return create_leaf(target_values) # Early stopping condition 2: Reached the minimum node size.
if reached_minimum_node_size(data, min_node_size):
return create_leaf(target_values) # Find the best splitting feature and split on the best feature.
splitting_feature = best_splitting_feature(data, features, target)
left_split = data[data[splitting_feature] == 0]
right_split = data[data[splitting_feature] == 1] # calculate error
error_before_split = intermediate_node_num_mistakes(target_values) / float(len(data))
left_mistakes = intermediate_node_num_mistakes(left_split[target])
right_mistakes = intermediate_node_num_mistakes(right_split[target])
error_after_split = (left_mistakes + right_mistakes) / float(len(data)) # Early stopping condition 3: Minimum error reduction
if error_before_split - error_after_split < min_error_reduction:
return create_leaf(target_values) remaining_features.remove(splitting_feature) # Repeat (recurse) on left and right subtrees
left_tree = decision_tree_create(left_split, remaining_features, target,
current_depth + 1, max_depth, min_node_size, min_error_reduction)
right_tree = decision_tree_create(right_split, remaining_features, target,
current_depth + 1, max_depth, min_node_size, min_error_reduction) return create_node(splitting_feature, left_tree, right_tree)
2. pruning
Total cost C(T) = Error(T) + λ L(T)

用建好的树预测数据:

def classify(tree, input):
# if the node is a leaf node.
if tree['is_leaf']:
return tree['prediction']
else:
# split on feature.
split_feature_value = input[tree['splitting_feature']]
if split_feature_value == 0:
return classify(tree['left'], input)
else:
return classify(tree['right'], input)
Classification week3: decision tree 笔记的更多相关文章
- OpenCV码源笔记——Decision Tree决策树
来自OpenCV2.3.1 sample/c/mushroom.cpp 1.首先读入agaricus-lepiota.data的训练样本. 样本中第一项是e或p代表有毒或无毒的标志位:其他是特征,可以 ...
- [ML学习笔记] 决策树与随机森林(Decision Tree&Random Forest)
[ML学习笔记] 决策树与随机森林(Decision Tree&Random Forest) 决策树 决策树算法以树状结构表示数据分类的结果.每个决策点实现一个具有离散输出的测试函数,记为分支 ...
- 【机器学习】决策树(Decision Tree) 学习笔记
[机器学习]决策树(decision tree) 学习笔记 标签(空格分隔): 机器学习 决策树简介 决策树(decision tree)是一个树结构(可以是二叉树或非二叉树).其每个非叶节点表示一个 ...
- 决策树学习笔记(Decision Tree)
什么是决策树? 决策树是一种基本的分类与回归方法.其主要有点事模型具有可得性,分类速度快.学习时,利用训练数据,根据损失函数最小化原则建立决策树模型:预测时,对新数据,利用决策树模型进行分类. 决策树 ...
- 机器学习技法笔记:09 Decision Tree
Roadmap Decision Tree Hypothesis Decision Tree Algorithm Decision Tree Heuristics in C&RT Decisi ...
- 机器学习技法笔记:11 Gradient Boosted Decision Tree
Roadmap Adaptive Boosted Decision Tree Optimization View of AdaBoost Gradient Boosting Summary of Ag ...
- Coursera台大机器学习技法课程笔记11-Gradient Boosted Decision Tree
将Adaboost和decision tree相结合,需要注意的地主是,训练时adaboost需要改变资料的权重,如何将有权重的资 料和decision tree相结合呢?方法很类似于前面讲过的bag ...
- [学习笔记] Uplift Decision Tree With KL Divergence
Uplift Decision Tree With KL Divergence Intro Uplift model 我没找到一个合适的翻译,这方法主要应用是,探究用户在给予一定激励之后的表现,也就是 ...
- 【3】Decision tree(决策树)
前言 Decision tree is one of the most popular classification tools 它用一个训练数据集学到一个映射,该映射以未知类别的新实例作为输入,输出 ...
随机推荐
- 学习实践:使用模式,原则实现一个C++数据库訪问类
一.概述 在我參与的多个项目中.大家使用libMySQL操作MySQL数据库,并且是源代码级复用,在多个项目中同样或相似的源代码.这种复用方式给开发带来了不便. libMySQL的使用比較麻烦.非常e ...
- c3p0配置详解<转贴>
<c3p0-config> <default-config> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数.Default: 3 --> < ...
- Druid对比Impala/Shark
Druid 和 Impala Shark 的对比取决于产品要求, 取决于系统是设计成做什么的 Druid 被设计成 一直在线, 高可用性 实时插入数据 分片分块形式的任意查询据我所知 Im ...
- Golang 内存热力图
https://cizixs.com/2017/09/11/profiling-golang-program/
- RocketMQ性能压测分析(转)
原创文章,转载请注明出处:http://jameswxx.iteye.com/blog/2093785 一 机器部署 1.1 机器组成 1台nameserver 1台broker 异步刷盘 2 ...
- 最小生成树之Prim(普里姆)算法
关于什么是Prim(普里姆算法)? 在实际生活中,我们常常碰到类似这种一类问题:如果要在n个城市之间建立通信联络网, 则连通n个城市仅仅须要n-1条线路.这时.我们须要考虑这样一个问题.怎样在最节省经 ...
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-T_AmsNetID是什么
该参数是包含六个数字类似于IP地址的字符串形式,例如"1.1.1.2.7.1",如果为空字符串,则默认使用本机的AmsNetID 你可以右击贝福的图标,然后点击About查看当前本 ...
- python抓包截取http记录日志
#!/usr/bin/python import pcap import dpkt import re def main(): pc=pcap.pcap(name="eth1" ...
- C++中string.find()函数与string::npos
先说说string::npos参数: npos 是一个常数,用来表示不存在的位置,类型一般是std::container_type::size_type 许多容器都提供这个东西.取值由实现决定,一般是 ...
- 由friend用法引出的声明与定义那些事儿
今天遇到了一个问题,大致描述一下就是有两个类A和B.我想达到如下效果:B是A的友元,同时A是B的类类型成员. 第一次尝试,在B.h中包含A.h,在A.h中包含B.h,在A类中声明friend clas ...