华盛顿大学 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. Fedora 修改时区、日期、时间

    # tzselect 修改时间命令 [root@comput1 ~]# tzselectPlease identify a location so that time zone rules can b ...

  2. linux 关闭端口

    第一步查看那些程序在使用该端口 netstat -anp或者netstat -tulnp 第二步杀死进程 kill -9 xxx,杀死某个进程 killall 进程名

  3. javascript快速入门12--函数式与面向对象

    函数 函数是一组可以随时随地运行的语句. 函数是 ECMAScript 的核心. 创建函数 function fnOne() {//具有名称的函数,函数名必须符合变量名命名规范 //可以没有符何语句 ...

  4. [Python爬虫] 之十八:Selenium +phantomjs 利用 pyquery抓取电视之家网数据

    一.介绍 本例子用Selenium +phantomjs爬取电视之家(http://www.tvhome.com/news/)的资讯信息,输入给定关键字抓取资讯信息. 给定关键字:数字:融合:电视 抓 ...

  5. replace的用法

    http://blog.sina.com.cn/s/blog_9ed9ac7d0101ec1f.html replace 语句 如果存在,更新,否则,插入在使用REPLACE时,表中必须有唯一索引,而 ...

  6. 使用Nginx+uWSGI+Django方法部署Django程序(上)

    Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.ng ...

  7. AutoResponder及正则表达式

    使用AutoResponder选项卡,你可以创建一个匹配规则和一个响应字符串,如果请求的URL地址跟你的匹配规则相匹配,Fiddler就会自动执行这个对应的响应字符串. 小提示: 匹配规则会按照它在规 ...

  8. 移动端H5页面 input 获取焦点时,虚拟键盘挡住input输入框解决方法

    在移动端h5开发的时候,发现如果input在页面底部,当触发input焦点的时候会弹出系统虚拟键盘,虚拟键盘会遮挡input输入框.这会很影响用户体验,于是在网上找到了如下的解决办法: 方法一:使用w ...

  9. Python趣味实用小工具

    代码地址如下:http://www.demodashi.com/demo/12918.html python 趣味实用小工具 概述 用python实现的三个趣味实用小工具: 图片转Execl工具 , ...

  10. node.js零基础详细教程(2):模块化、fs文件操作模块、http创建服务模块

    第二章  建议学习时间4小时  课程共10章 学习方式:详细阅读,并手动实现相关代码 学习目标:此教程将教会大家 安装Node.搭建服务器.express.mysql.mongodb.编写后台业务逻辑 ...