matlab创建决策树算法

南城旧安 2016-09-29 04:11:05

我想请问一下,为什么C4.5会出现这个错误
...全文
559 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
实验三 决策树算法实验 一、实验目的: 熟悉和掌握决策树的分类原理、实质和过程;掌握典型的学习算法 和实现技术。 二、实验原理: 决策树学习和分类. 三、实验条件: 四、实验内容: 1 根据现实生活中的原型自己创建一个简单的决策树。 2 要求用这个决策树能解决实际分类决策问题。 五、实验步骤: 1、验证性实验: (1)算法伪代码 算法Decision_Tree(data,AttributeName) 输入由离散值属性描述的训练样本集data; 候选属性集合AttributeName。 输出一棵决策树。 (1) 创建节点N; (2) If samples 都在同一类C中then (3) 返回N作为叶节点,以类C标记; (4) If attribute_list为空then (5) 返回N作为叶节点,以samples 中最普遍的类标记;//多数表决 (6) 选择attribute_list 中具有最高信息增益的属性test_attribute; (7) 以test_attribute 标记节点N; (8) For each test_attribute 的已知值v //划分 samples ; (9) 由节点N分出一个对应test_attribute=v的分支; (10令Sv为 samples中 test_attribute=v 的样本集合;//一个划分块 (11)If Sv为空 then (12)加上一个叶节点,以samples中最普遍的类标记; (13)Else 加入一个由Decision_Tree(Sv,attribute_list- test_attribute)返回节点值。 (2)实验数据预处理 Age:30岁以下标记为"1";30岁以上50岁以下标记为"2";50岁以上标记为"3"。 Sex:F EMAL----"1";MALE----"2" Region:INNER CITY----"1";TOWN----"2"; RURAL----"3"; SUBURBAN---- "4" Income:5000~2万----"1";2万~4万----"2";4万以上---- "3" Married Children Car Mortgage Pep:以上五个条件,若为"是"标记为"1",若为"否"标记为"2"。 Age sex region income married children car mortgage pep 1 2 1 1 2 1 1 2 2 1 2 1 1 2 2 2 2 1 2 1 4 1 2 1 2 2 1 2 1 1 1 1 2 2 2 2 1 2 1 1 1 2 2 2 2 1 2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 1 2 2 1 1 1 2 1 1 2 1 2 1 3 1 2 2 1 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 2 2 2 1 1 2 1 2 2 1 1 2 1 1 2 2 1 2 1 2 2 1 2 1 1 1 2 1 2 2 2 1 3 2 1 2 1 1 1 2 2 1 1 1 2 1 1 1 2 1 1 1 3 2 2 2 1 2 1 3 1 2 2 1 2 2 2 1 3 2 3 3 1 1 1 2 1 3 2 2 3 1 2 1 1 2 3 1 3 3 1 1 2 2 1 3 2 1 3 1 2 1 2 2 3 2 1 3 1 1 1 1 1 3 1 1 3 1 2 1 1 2 3 1 3 3 1 2 2 2 2 3 2 4 3 1 2 2 1 1 3 1 3 3 2 2 1 1 2 (3)Matlab语句: [Tree RulesMatrix]= DecisionTree(DataSet, AttributName); 六、实验结果: 实验程序: function [Tree RulesMatrix]=DecisionTree(DataSet,AttributName) %输入为训练集,为离散后的数字,如记录1:1 1 3 2 1; %前面为属性列,最后一列为类标 if nargin<1 error('请输入数据集'); else if isstr(DataSet) [DataSet AttributValue]=readdata2(DataSet); else AttributValue=[]; end end if nargin<2 AttributName=[]; end Attributs=[1:size(DataSet,2)-1]; Tree=CreatTree(DataSet,Attributs); disp([char(13) 'The Decision Tree:']); showTree(Tree,0,0,1,Attr

3,423

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 其他开发语言
社区管理员
  • 其他开发语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧