决策树java代码

决策树java代码

ID:38587845

大小:59.50 KB

页数:11页

时间:2019-06-15

决策树java代码_第1页
决策树java代码_第2页
决策树java代码_第3页
决策树java代码_第4页
决策树java代码_第5页
资源描述:

《决策树java代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、importjava.util.HashMap;importjava.util.HashSet;importjava.util.Iterator;importjava.util.LinkedHashSet;classTreeNode{Stringelement;//该值为数据的属性名称Stringvalue;//上一个分裂属性在此结点的值LinkedHashSetchilds;//结点的子结点,以有顺序的链式哈希集存储publicTreeNode(){this.element=null;this.value=nu

2、ll;this.childs=null;}publicTreeNode(Stringvalue){this.element=null;this.value=value;this.childs=null;}publicStringgetElement(){returnthis.element;}publicvoidsetElement(Stringe){this.element=e;}publicStringgetValue(){returnthis.value;}publicvoidsetValue(Stringv){this.va

3、lue=v;}publicLinkedHashSetgetChilds(){returnthis.childs;}publicvoidsetChilds(LinkedHashSetchilds){this.childs=childs;}}//决策树类classDecisionTree{TreeNoderoot;//决策树的树根结点publicDecisionTree(){root=newTreeNode();}publicDecisionTree(TreeNoderoot){this.root

4、=root;}publicTreeNodegetRoot(){returnroot;}publicvoidsetRoot(TreeNoderoot){this.root=root;}publicStringselectAtrribute(TreeNodenode,String[][]deData,booleanflags[],LinkedHashSetatrributes,HashMapattrIndexMap){//Gain数组存放当前结点未分类属性的Gain值doubleGain[

5、]=newdouble[atrributes.size()];//每条数据中归类的下标,为每条数据的最后一个值intclass_index=deData[0].length-1;//属性名,该结点在该属性上进行分类Stringreturn_atrribute=null;//计算每个未分类属性的Gain值intcount=0;//计算到第几个属性for(Stringatrribute:atrributes){//该属性有多少个值,该属性有多少个分类intvalues_count,class_count;//属性值对应的下标intind

6、ex=attrIndexMap.get(atrribute);//存放属性的各个值和分类值LinkedHashSetvalues=newLinkedHashSet();LinkedHashSetclasses=newLinkedHashSet();for(inti=0;i

7、]);}}values_count=values.size();class_count=classes.size();intvalues_vector[]=newint[values_count*class_count];intclass_vector[]=newint[class_count];for(inti=0;i

8、{j++;}}intk=0;for(Stringc:classes){if(deData[i][class_index].equals(c)){break;}else{k++;}}values_vector[j*class_count

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。