c4.5决策树 java_【决策树】— C4.5算法建立决策树JAVA练习

这是一个关于使用Java实现C4.5决策树算法的博客。作者提供了一个简单的数据集,并展示了如何创建决策树的过程,包括计算信息增益、选择最佳属性、递归构建子树等关键步骤。博客还包含了`DecisionTree`和`InfoGain`两个核心类的代码实现,用于构建和计算决策树。
摘要由CSDN通过智能技术生成

以下程序是我练习写的,不一定正确也没做存储优化。有问题请留言交流。转载请挂连接。

当前的属性为:age income student credit_rating

当前的数据集为(最后一列是TARGET_VALUE):

---------------------------------

youth     high   no   fair      no

youth     high   no   excellent   no

middle_aged   high   no   fair     yes

senior     low    yes  fair     yes

senior     low    yes  excellent   no

middle_aged   low    yes  excellent   yes

youth     medium  no   fair     no

youth     low     yes  fair     yes

senior     medium  yes    fair     yes

youth     medium  yes    excellent   yes

middle_aged   high   yes  fair        yes

senior     medium  no     excellent   no

---------------------------------

C4.5建立树类

packageC45Test;importjava.util.ArrayList;importjava.util.List;importjava.util.Map;public classDecisionTree {public TreeNode createDT(List> data,ListattributeList){

System.out.println("当前的DATA为");for(int i=0;i

ArrayList temp =data.get(i);for(int j=0;j

System.out.print(temp.get(j)+ " ");

}

System.out.println();

}

System.out.println("---------------------------------");

System.out.println("当前的ATTR为");for(int i=0;i

System.out.print(attributeList.get(i)+ " ");

}

System.out.println();

System.out.println("---------------------------------");

TreeNode node= newTreeNode();

String result=InfoGain.IsPure(InfoGain.getTarget(data));if(result != null){

node.setNodeName("leafNode");

node.setTargetFunValue(result);returnnode;

}if(attributeList.size() == 0){

node.setTargetFunValue(result);returnnode;

}else{

InfoGain gain= newInfoGain(data,attributeList);double maxGain = 0.0;int attrIndex = -1;for(int i=0;i

maxGain=tempGain;

attrIndex=i;

}

}

System.out.println("选择出的最大增益率属性为: " +attributeList.get(attrIndex));

node.setAttributeValue(attributeList.get(attrIndex));

List> resultData = null;

Map attrvalueMap =ga

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值