欢迎来到天天文库
浏览记录
ID:46882928
大小:91.00 KB
页数:10页
时间:2019-11-28
《C45算法建立决策树JAVA练习》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、以下程序是我练习写的,不一定正确也没做存储优化。侑问题请留言交流。转载请挂连接。当前的属性为:ageincomestudentcredit_rating当前的数据集为(最后一列是TARGET_VALUE):youthhighnofairnoyouthhighnoexcellentnomiddle_agedhighnofairyesseniorlowyesfairyesseniorlowyesexcellentnomiddle_agedlowyesexcellentyesyouthmediumnofairnoyouthlowyesfairyesseniormediumyesfai
2、ryesyouthmediumyesexcellentyesmiddle_agedhighyesfairyesseniormediumnoexcellentnoC4.5建立树类packageC45Test;importjava,util.AirayList;importjava.util.List;importjava.util.Map;publicclassDecisionTree{publicTreeNodecreateDT(List〈ArrayList〈String»data,ListattributeList){System,out.println(z,
3、当前的DATA为〃);for(inti=0;itemp=data,get(i);for(intj二0;j〈temp.size();j++){System.out.print(temp,get(j)+"“);}System,out.println();System,out.println(〃System,out.println(z,当前的ATTR为〃);for(inti二0;i4、;}System,out.println();System,out.printin(,z〃);TreeNodenode=newTreeNode();Stringresult=InfoGain.IsPure仃nfoGain.getTarget(data));if(result!=null){node.setNodeName(zzleafNode,/);node.setTargetFunValue(result);returnnode;}if(attributeList.size()二二0){node.setTargetFunValue(result);returnnode;}el5、se{TnfoGaingain二newTnfoGain(data,attributeList);doublemaxGain=0.0;intattrIndex=-1;for(inti=0;i〈attributeList.size();i++){doubletempGain二gain.getGainRatio(i);if(maxGain6、Value(attributeList.get(attrlndex));List〈ArrayList〈String>>resultDato=null;MapattrvalueMap二gain.getAttributeValue(attrlndex);for(Map.Entryentry:attrvalucMap.entrySet()){resultData二gain.getData4Value(entry.getKeyO,attrlndex);TreeNodeleafNode二null;System.out.println("7、当前为z,+attributeList.get(attrlndex)+z,的〃+entry.getKey()+〃分支。“);if(resultDatei.size()==0){leafNode二newTreeNode();leafNode.setNodeName(attributeList.get(attrlndex));leafNode.setTargetFunValue(result);leafNode.setAttributeValue(entry.getKey());}else{fo
4、;}System,out.println();System,out.printin(,z〃);TreeNodenode=newTreeNode();Stringresult=InfoGain.IsPure仃nfoGain.getTarget(data));if(result!=null){node.setNodeName(zzleafNode,/);node.setTargetFunValue(result);returnnode;}if(attributeList.size()二二0){node.setTargetFunValue(result);returnnode;}el
5、se{TnfoGaingain二newTnfoGain(data,attributeList);doublemaxGain=0.0;intattrIndex=-1;for(inti=0;i〈attributeList.size();i++){doubletempGain二gain.getGainRatio(i);if(maxGain6、Value(attributeList.get(attrlndex));List〈ArrayList〈String>>resultDato=null;MapattrvalueMap二gain.getAttributeValue(attrlndex);for(Map.Entryentry:attrvalucMap.entrySet()){resultData二gain.getData4Value(entry.getKeyO,attrlndex);TreeNodeleafNode二null;System.out.println("7、当前为z,+attributeList.get(attrlndex)+z,的〃+entry.getKey()+〃分支。“);if(resultDatei.size()==0){leafNode二newTreeNode();leafNode.setNodeName(attributeList.get(attrlndex));leafNode.setTargetFunValue(result);leafNode.setAttributeValue(entry.getKey());}else{fo
6、Value(attributeList.get(attrlndex));List〈ArrayList〈String>>resultDato=null;MapattrvalueMap二gain.getAttributeValue(attrlndex);for(Map.Entryentry:attrvalucMap.entrySet()){resultData二gain.getData4Value(entry.getKeyO,attrlndex);TreeNodeleafNode二null;System.out.println("
7、当前为z,+attributeList.get(attrlndex)+z,的〃+entry.getKey()+〃分支。“);if(resultDatei.size()==0){leafNode二newTreeNode();leafNode.setNodeName(attributeList.get(attrlndex));leafNode.setTargetFunValue(result);leafNode.setAttributeValue(entry.getKey());}else{fo
此文档下载收益归作者所有