cart算法实例matlab,matlab 决策树cart算法源代码
matlab源码 决策树 c4.5 cart
function D = CART(train_features, train_targets, params, region)
% Classify using classification and regression trees
% Inputs:
% features - Train features
% targets - Train targets
% params - [Impurity type, Percentage of incorrectly assigned samples at a node]
% Impurity can be: Entropy, Variance (or Gini), or Missclassification
% region - Decision region vector: [-x x -y y number_of_points]
%
% Outputs
% D - Decision sufrace
[Ni, M] = size(train_features);
%Get parameters
[split_type, inc_node] = process_params(params);
%For the decision region
N = region(5);
mx = ones(N,1) * linspace (region(1),region(2),N);
my = linspace (region(3),region(4),N)' * ones(1,N);
flatxy = [mx(:), my(:)]';
%Preprocessing
[f, t, UW, m] = PCA(train_features, train_targets, Ni, region);
train_features = UW * (train_features - m*ones(1,M));;
flatxy = UW * (flatxy - m*ones(1,N^2));;
%Build the tree recursively
disp('Building tree')
tree = make_tree(train_features, train_targets, M, split_type, inc_node, region);
%Make the decision region according to the tree
disp('Building decision surface using the tree')
targets = use_tree(flatxy, 1:N^2, tree);
D = reshape(targets,N,N);
%END
function targets = use_tree(features, indices, tree)
%Classify recursively using a tree
if isnumeric(tree.Raction)
%Reached an end node
targets = zeros(1,size(features,2));
targets(indices) = tree.Raction(1);
else
%Reached a branching, so:
%Find who goes where
in_right = indices(find(eval(tree.Raction)));
in_left = indices(find(eval(http://doc.docsou.comction)));
Ltargets = use_tree(features, in_left, tree.left);
Rtargets = use_tree(features, in_right, tree.right);
targets = Ltargets + Rtargets;
end
%END use_tree
function tree = make_tree(features, targets, Dlength, split_type, inc_node, region)
%Build a tree recursively
if (length(unique(targets)) == 1),
%There is only one type of targets, and this generates a warning, so deal with it separately
tree.right = [];
tree.left = [];
tree.Raction = targets(1);
http://doc.docsou.comction = targets(1);
break
end
[Ni, M] = size(features);
Nt = unique(targets);
N = hist(targets, Nt);
if ((sum(N < Dlength*inc_node) == length(Nt) - 1) | (M == 1)),
%No further splitting is neccessary
tree.right = [];
tree.left = [];
if (length(Nt) ~= 1),
MLlabel = find(N == max(N));
else
MLlabel = 1;
end
tree.Raction = Nt(MLlabel);
http://doc.docsou.comction = Nt(MLlabel);
else
%Split the node according to the splitting criterion
deltaI = zeros(1,Ni);
split_point = zeros(1,Ni);
op = optimset('Display', 'off');
for i = 1:Ni,
split_point(i) = fminbnd('CARTfunctions', region(i*2-1), region(i*2), op, features, targets, i, split_type);
cart算法实例matlab,matlab 决策树cart算法源代码相关推荐
- 人工神经网络算法实例代码,人工神经网络算法步骤
神经网络算法实例说明有哪些? 在网络模型与算法研究的基础上,利用人工神经网络组成实际的应用系统,例如,完成某种信号处理或模式识别的功能.构作专家系统.制成机器人.复杂系统控制等等. 纵观当代新兴科学技 ...
- 神经网络算法实例说明,简单神经网络算法原理
神经网络算法实例说明有哪些? 在网络模型与算法研究的基础上,利用人工神经网络组成实际的应用系统,例如,完成某种信号处理或模式识别的功能.构作专家系统.制成机器人.复杂系统控制等等. 纵观当代新兴科学技 ...
- knn算法实例python_Python实现的knn算法示例
本文实例讲述了Python实现的knn算法.分享给大家供大家参考,具体如下: 代码参考机器学习实战那本书: 有兴趣你们可以去了解下 具体代码: # -*- coding:utf-8 -*- #! py ...
- java实现lz77算法实例_数据压缩算法---LZ77算法 的分析与实现
LZ77简介 Ziv和Lempel于1977年发表题为"顺序数据压缩的一个通用算法(A Universal Algorithm for Sequential Data Compression ...
- 最短移臂调度算法_MATLAB优化算法实例——蚁群算法
❝ 欢迎关注「工科男的Maltab学习日志」,采用Mardown文本编辑器编写文章,全新排版升级,内容.代码更简洁,同时开通了视频号,「工科男的日常」欢迎大家关注. --工科男 ❞ 1 蚁群算法基本理 ...
- linux加密框架 crypto 算法管理 - 创建哈希算法实例
crypto_alloc_ahash函数 加密框架中的哈希算法可以是同步方式实现的也可以是异步方式实现的,但是算法应用不关注哈希算法的实现方式,关注的是哈希算法提供的算法接口.为实现统一管理,加密框架 ...
- 随机森林实例:利用基于CART算法的随机森林(Random Forest)树分类方法对于红酒质量进行预测
随机森林实例:利用基于CART算法的随机森林(Random Forest)树分类方法对于红酒质量进行预测 1.引言 2.理论基础 2.1 什么是决策树 2.2 特征选择的算法 2.2.1 ID3:基于 ...
- 分类算法之决策树CART算法
1. CART算法的认识 Classification And Regression Tree,即分类回归树算法,简称CART算法,它是决策树的一种实现,通常决策树主要有三种实现,分别是ID3算法,C ...
- 机器学习第五篇:详解决策树-CART算法
01|前言: 本篇接着上一篇决策树详解,CART是英文"classification and regression tree"的缩写,翻译过来是分类与回归树,与前面说到的ID3.C ...
- 决策树-CART算法
总第80篇 01|前言: 本篇接着上一篇决策树详解,CART是英文"classification and regression tree"的缩写,翻译过来是分类与回归树,与前面说到 ...
最新文章
- 云计算读书笔记(二)
- 因一个计算机故障而“停工”!观测宇宙 30 多年的哈勃太空望远镜还能坚持多久?...
- 编程珠玑第七章 粗略估算
- python简单代码画皮卡丘-实现童年宝可梦,教你用Python画一只属于自己的皮卡丘...
- 浅析C#的事件处理和自定义事件
- 计算机四级软件工程知识点,计算机四级考试题库及搜题软件,送一份备考指南给大家!...
- osg学习笔记(一)
- 判断Python输入是否为数字
- 与ceph的区别_Ceph分布式存储高性能设计
- android c博客园,android上进行c/C 开发测试(转) - 奋进 - 博客园
- 配置jboss,mysql,seam,eclipse步骤(一)
- 【比赛】NOIP2017 列队
- linux网络服务学习笔记--基本网络配置
- NodeMCU ESP8266+Arduino:将宿舍老式门锁改造为简易密码锁
- 如何增加mysql字段长度_增加数据库字段长度
- Skywalking应用
- 三星手机html默认,三星手机默认播放器使用方法
- ios 穿山甲广告联盟集成_GitHub - ducaiwei/Pangolin: Flutter 广告SDK-字节跳动-穿山甲 集成...
- 小程序上传头像图片裁剪
- 解决Win10桌面右键卡顿一直转圈圈的问题