华盛顿大学 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 笔记的更多相关文章

  1. OpenCV码源笔记——Decision Tree决策树

    来自OpenCV2.3.1 sample/c/mushroom.cpp 1.首先读入agaricus-lepiota.data的训练样本. 样本中第一项是e或p代表有毒或无毒的标志位:其他是特征,可以 ...

  2. [ML学习笔记] 决策树与随机森林(Decision Tree&Random Forest)

    [ML学习笔记] 决策树与随机森林(Decision Tree&Random Forest) 决策树 决策树算法以树状结构表示数据分类的结果.每个决策点实现一个具有离散输出的测试函数,记为分支 ...

  3. 【机器学习】决策树(Decision Tree) 学习笔记

    [机器学习]决策树(decision tree) 学习笔记 标签(空格分隔): 机器学习 决策树简介 决策树(decision tree)是一个树结构(可以是二叉树或非二叉树).其每个非叶节点表示一个 ...

  4. 决策树学习笔记(Decision Tree)

    什么是决策树? 决策树是一种基本的分类与回归方法.其主要有点事模型具有可得性,分类速度快.学习时,利用训练数据,根据损失函数最小化原则建立决策树模型:预测时,对新数据,利用决策树模型进行分类. 决策树 ...

  5. 机器学习技法笔记:09 Decision Tree

    Roadmap Decision Tree Hypothesis Decision Tree Algorithm Decision Tree Heuristics in C&RT Decisi ...

  6. 机器学习技法笔记:11 Gradient Boosted Decision Tree

    Roadmap Adaptive Boosted Decision Tree Optimization View of AdaBoost Gradient Boosting Summary of Ag ...

  7. Coursera台大机器学习技法课程笔记11-Gradient Boosted Decision Tree

    将Adaboost和decision tree相结合,需要注意的地主是,训练时adaboost需要改变资料的权重,如何将有权重的资 料和decision tree相结合呢?方法很类似于前面讲过的bag ...

  8. [学习笔记] Uplift Decision Tree With KL Divergence

    Uplift Decision Tree With KL Divergence Intro Uplift model 我没找到一个合适的翻译,这方法主要应用是,探究用户在给予一定激励之后的表现,也就是 ...

  9. 【3】Decision tree(决策树)

    前言 Decision tree is one of the most popular classification tools 它用一个训练数据集学到一个映射,该映射以未知类别的新实例作为输入,输出 ...

随机推荐

  1. python的dict如何排序

    Python的内置dictionary数据类型是无序的,通过key来获取对应的value.可是有时我们需要对dictionary中 的item进行排序输出,可能根据key,也可能根据value来排 # ...

  2. Linux下sqlite3编程

    ---------------------------------------------------------------------------------------------------- ...

  3. 阿里云RDS(云数据库)之产品简介

    参考阿里产品文档:https://docs.aliyun.com/?spm=5176.100054.3.1.ywnrMX#/pub/rds/product-introduce/overview& ...

  4. Spark Streaming揭秘 Day1-三大谜团

    Spark Streaming揭秘 Day1 三大谜团 引子 在Spark的众多组件中,Streaming最接近企业级应用程序,学习Spark Streaming,是掌握大数据技术的一条捷径.今天是第 ...

  5. B8:中介者模式 Mediator

    用一个中介对象来封装一系列的对象交互,中介者使得各对象不需要显示地相互引用,从而使其耦合松散,而且可以独立的改变它们之间的交互. 减少了各对象之间的耦合,使得可以独立的改变或复用各个Mediator或 ...

  6. java web程序中项目名的更改(http://localhost:8080/)后面的名字

    在MyEclipse中的Web项目,如果想另换名称(Context-root)进行发布,可以在项目的属性中进行设置.设置路径如下: 右击项目XX(或选中项目XX,按快捷键Alt+Enter), 打开项 ...

  7. PJOI PKU Campus 2011 B:A Problem about Tree LCA 求随意点x为根的y的父节点

    题目链接:点击打开链接 题意:给定n个点 m个询问 以下n-1行给定一棵树 m个询问 x y 问把树转成以x为根 y的父节点是谁 第一种情况lca==y那就是x的第 dep[x] - dep[y] - ...

  8. JSON——JavaScript 中的使用

    由于JSON非常简单,很快就风靡Web世界,并且成为ECMA标准.几乎所有编程语言都有解析JSON的库,而在JavaScript中,我们可以直接使用JSON,因为JavaScript内置了JSON的解 ...

  9. SSH框架中POJO层, Dao层,Service层, Action层的功能理解

    pojo层就是对应的数据库表的实体类(如User类). dao层,一般可以再分为***dao接口和***daoImpl实现类,如userDao接口和userDaoImpl实现类,接口负责定义数据库cu ...

  10. UnicodeEncodeError: ‘gbk’ codec can’t encode character u’\u200e’ in position 43: illegal multibyte sequence

    [问题] python中已获取网页: http://blog.csdn.net/hfahe/article/details/5494895 的html源码,其时UTF-8编码的. 提取出其标题部分: ...