C45算法建立决策树JAVA练习DOCWord文档下载推荐.docx

上传人:b****2 文档编号:12935447 上传时间:2022-09-30 格式:DOCX 页数:15 大小:15.31KB
下载 相关 举报
C45算法建立决策树JAVA练习DOCWord文档下载推荐.docx_第1页
第1页 / 共15页
C45算法建立决策树JAVA练习DOCWord文档下载推荐.docx_第2页
第2页 / 共15页
C45算法建立决策树JAVA练习DOCWord文档下载推荐.docx_第3页
第3页 / 共15页
C45算法建立决策树JAVA练习DOCWord文档下载推荐.docx_第4页
第4页 / 共15页
C45算法建立决策树JAVA练习DOCWord文档下载推荐.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

C45算法建立决策树JAVA练习DOCWord文档下载推荐.docx

《C45算法建立决策树JAVA练习DOCWord文档下载推荐.docx》由会员分享,可在线阅读,更多相关《C45算法建立决策树JAVA练习DOCWord文档下载推荐.docx(15页珍藏版)》请在冰豆网上搜索。

C45算法建立决策树JAVA练习DOCWord文档下载推荐.docx

youth    medium 

no fair    no 

youth    low   

yes fair    yes 

senior    medium 

yes 

fair    yes 

yes 

excellent yes 

high  yes fair 

   yes 

no 

excellent no 

C4.5建立树类

packageC45Test;

importjava.util.ArrayList;

importjava.util.List;

importjava.util.Map;

publicclassDecisionTree{

publicTreeNodecreateDT(List<

ArrayList<

String>

>

data,List<

attributeList){

System.out.println("

当前的DATA为"

);

for(inti=0;

i<

data.size();

i++){

ArrayList<

temp=data.get(i);

for(intj=0;

j<

temp.size();

j++){

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

"

}

System.out.println();

---------------------------------"

当前的ATTR为"

attributeList.size();

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

TreeNodenode=newTreeNode();

Stringresult=InfoGain.IsPure(InfoGain.getTarget(data));

if(result!

=null){

node.setNodeName("

leafNode"

node.setTargetFunValue(result);

returnnode;

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

}else{

InfoGaingain=newInfoGain(data,attributeList);

doublemaxGain=0.0;

intattrIndex=-1;

doubletempGain=gain.getGainRatio(i);

if(maxGain<

tempGain){

maxGain=tempGain;

attrIndex=i;

选择出的最大增益率属性为:

+attributeList.get(attrIndex));

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

List<

resultData=null;

Map<

String,Long>

attrvalueMap=gain.getAttributeValue(attrIndex);

for(Map.Entry<

String,Long>

entry:

attrvalueMap.entrySet()){

resultData=gain.getData4Value(entry.getKey(),attrIndex);

TreeNodeleafNode=null;

当前为"

+attributeList.get(attrIndex)+"

的"

+entry.getKey()+"

分支。

"

if(resultData.size()==0){

leafNode=newTreeNode();

leafNode.setNodeName(attributeList.get(attrIndex));

leafNode.setTargetFunValue(result);

leafNode.setAttributeValue(entry.getKey());

for(intj=0;

j<

resultData.size();

j++){

resultData.get(j).remove(attrIndex);

resultAttr=newArrayList<

(attributeList);

resultAttr.remove(attrIndex);

leafNode=createDT(resultData,resultAttr);

node.getChildTreeNode().add(leafNode);

node.getPathName().add(entry.getKey());

classTreeNode{

privateStringattributeValue;

privateList<

TreeNode>

childTreeNode;

pathName;

privateStringtargetFunValue;

privateStringnodeName;

publicTreeNode(StringnodeName){

this.nodeName=nodeName;

this.childTreeNode=newArrayList<

();

this.pathName=newArrayList<

publicTreeNode(){

publicStringgetAttributeValue(){

returnattributeValue;

publicvoidsetAttributeValue(StringattributeValue){

this.attributeValue=attributeValue;

publicList<

getChildTreeNode(){

returnchildTreeNode;

publicvoidsetChildTreeNode(List<

childTreeNode){

this.childTreeNode=childTreeNode;

publicStringgetTargetFunValue(){

returntargetFunValue;

publicvoidsetTargetFunValue(StringtargetFunValue){

this.targetFunValue=targetFunValue;

publicStringgetNodeName(){

returnnodeName;

publicvoidsetNodeName(StringnodeName){

getPathName(){

returnpathName;

publicvoidsetPathName(List<

pathName){

this.pathName=pathName;

}

增益率计算类(取log的时候底用的是e,没用2)

importjava.util.HashMap;

importjava.util.HashSet;

importjava.util.Iterator;

importjava.util.Set;

//C4.5实现

publicclassInfoGain{

data;

attribute;

publicInfoGain(List<

attribute){

this.data=newArrayList<

t=newArrayList<

t.add(temp.get(j));

this.data.add(t);

this.attribute=newArrayList<

St

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 营销活动策划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1