资源简介
使用matlab实现id3决策树算法,给出使用方法及举例,并附带相关测试集合。
代码片段和文件信息
%author: svmsunny
%mailto: chingsun00@gmail.com
classdef ID3Tree
properties
translator; %for translating the data type from string to number if necessary;
statistic_info; %for each dimension gather statistics
root;
train_set_dim;
end
methods
%function ========================================================
function obj = construct_tree(obj training_set data_type)
%training_set
%data_type: 1 for string and 0 for number. donnot consider
%the condition that some column are number and others are
%string.
%生成一个分类树
if data_type %translate the string data to number
translator = trans_data();
[trans_train obj.translator] = translator.translate_train(training_set);
clear training_set;
training_set = trans_train;
end
obj.train_set_dim = size(training_set2);
for i = 1 : size(training_set2) %column
clear table;
table = tabulate(training_set(:i));
cout = 1;
for j = 1 : size(table1) %
if table(j2) %not zero
statistic_info{1i}(1cout) = table(j1);
cout = cout + 1;
end
end
end
obj.statistic_info = statistic_info;
dim_visible = ones(1 size(training_set2)-1);
obj.root = make_tree(training_setdim_visiblestatistic_info);
end
%function ========================================================
function [cor_rationtargets] = classify(obj testing_set)
%
if ~isempty(obj.translator) % need to translate the data
trans_test = obj.translator.translate_test(testing_set);
clear testing_set;
testing_set = trans_test;
end
train_set_dimension = obj.train_set_dim; %include the class label column
classifier_tree = obj.root;
targets = zeros(size(testing_set1) 1);
for i = 1: size(testing_set 1)
targets(i 1) = classify_class(classifier_tree testing_set(i1:train_set_dimension-1));
end
if train_set_dimension == size(testing_set 2) %same dimension then get the correct ratio
cout = 0;
for i = 1: size(testing_set 1)
if testing_set(i end) == targets(i 1)
cout = cout + 1;
end
end
cor_ration = cout / size(testing_set 1);
else
cor_ration = -1; %not for testing the classifying Precision
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7972 2010-04-28 21:23 id3决策树\ID3Tree.m
文件 16416 2010-04-21 11:24 id3决策树\orig_abalone_test.txt
文件 62947 2010-04-21 11:25 id3决策树\orig_abalone_train.txt
文件 3317 2010-04-28 10:28 id3决策树\trans_data.m
文件 530 2010-04-28 21:19 id3决策树\usecase.m
目录 0 2010-04-28 21:20 id3决策树
----------- --------- ---------- ----- ----
91182 6
相关资源
- 地震数据的MATLAB中读取程序
- matlab中各种随机数的产生文件,其中
- 涡旋光束干涉图样计算程序
- matlab识别模态参数程序
- 物流选址的最优方案MATLAB程序
- EKF SLAM 例程matlab
- 使用matlab进行普朗克公式计算
- matlab的图像缩放和旋转代码
- matlab实验报告 很齐全
- MATLAB 希尔密码体系程序源码
- matlab实现模糊神经网络
- matlab实现矩阵归一化源代码
- matlab图像形状识别
- 关于BF硬判决的编码以及仿真
- PRML全部代码
- 凸集投影法POCS超分辨重建算法MATLAB实
- 小波变换(去噪融合)和卡尔曼滤波
- matlab通信编程IQ解调
- 三相光伏逆变并网 仿真
- EEMD matlab 工具包
- 基于Matlab语言的蒙特卡洛仿真入门教
- graph cut matlab 代码 可以运行 能直观看
- matlab code for water-filling using binary sea
- 用matlab实现音频水印的嵌入与提取
- matlab实现阻抗圆图源代码
- 精通MATLAB最优化计算源代码
- 自适应卡尔曼滤波器的matlab实现
- hmm算法matlab实现和
- 思典-粒子群优化Matlab工具箱
- 实现2DPSK功能的matlab程序
评论
共有 条评论