• 大小: 49KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-04
  • 语言: Java
  • 标签:

资源简介

决策树算法的java实现,包括C4.5和ID3的实现。

资源截图

代码片段和文件信息

package com.decisionTree.C45;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.TreeSet;
public class C45 {
private DecisionTreeNode root;
private boolean[] visable;  
private static final int NOT_FOUND = -1;  
private static final int DATA_START_LINE = 1;  
private object[] trainingArray;  
private String[] columnHeaderArray;  
private int nodeIndex;  
/** 
     * @param args 
     */ 
@SuppressWarnings(“boxing“)   
public static void main(String[] args) {   
        object[] array = new object[] {   
new String[] { “age“          “income“   “student“ “credit_rating“ “buys_computer“ }   
new String[] { “youth“        “high“     “no“      “fair“          “no“  }   
new String[] { “youth“        “high“     “no“      “excellent“     “no“  }   
new String[] { “middle_aged“  “high“     “no“      “fair“          “yes“ }   
new String[] { “senior“       “medium“   “no“      “fair“          “yes“ }   
new String[] { “senior“       “low“      “yes“     “fair“          “yes“ }   
new String[] { “senior“       “low“      “yes“     “excellent“     “no“  }   
new String[] { “middle_aged“  “low“      “yes“     “excellent“     “yes“ }   
new String[] { “youth“        “medium“   “no“      “fair“          “no“  }   
new String[] { “youth“        “low“      “yes“     “fair“          “yes“ }   
new String[] { “senior“       “medium“   “yes“     “fair“          “yes“ }   
new String[] { “youth“        “medium“   “yes“     “excellent“     “yes“ }   
new String[] { “middle_aged“  “medium“   “no“      “excellent“     “yes“ }   
new String[] { “middle_aged“  “high“     “yes“     “fair“          “yes“ }   
new String[] { “senior“       “medium“   “no“      “excellent“     “no“  }   
        };  

        C45 tree = new C45();   
        tree.create(array 4);   
        System.out.println(“===============END PRINT TREE===============“);   
        System.out.println(“===============DECISION RESULT===============“);   
        //tree.forecast(printData tree.root); 
    }  


/** 
 * @param printData 
 * @param node 
 */ 
public void forecast(String[] printData DecisionTreeNode node) {   
int index = getColumnHeaderIndexByName(node.nodeName);   
if (index == NOT_FOUND) {   
        System.out.println(node.nodeName);   
    }   
    DecisionTreeNode[] childs = node.childNodesArray;   
for (int i = 0; i < childs.length; i++) {   
if (childs[i] != null) {   
if (childs[i].parentArrtibute.equals(printData[index])) {   
                forecast(printData childs[i]);   
            }   
        }   
    }   
}  

/** 
 * @param array 
 * @param index 
 */ 
public void create(object[] array int index) {   
this.trainingArray = Arrays.copyOfRange(array DATA_START_LINE   
            array.length);   
    init(array index);   
    createDecisionTree(this

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-04-17 19:41  DecisionTree\
     文件         232  2017-02-27 16:29  DecisionTree\.classpath
     文件         388  2017-02-27 16:29  DecisionTree\.project
     目录           0  2017-04-17 19:41  DecisionTree\.settings\
     文件          90  2017-04-17 19:41  DecisionTree\.settings\org.eclipse.core.resources.prefs
     目录           0  2017-04-17 19:39  DecisionTree\bin\
     目录           0  2017-04-17 19:39  DecisionTree\bin\com\
     目录           0  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\
     目录           0  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\C45\
     文件        8485  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\C45\C45.class
     文件         519  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\C45\DecisionTreeNode.class
     文件         726  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\C45\DecisionTreeUtil.class
     文件         714  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\C45\SequenceComparator.class
     目录           0  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3\
     文件        1408  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3\DecisionTree$Sample.class
     文件        1353  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3\DecisionTree$Tree.class
     文件        8604  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3\DecisionTree.class
     目录           0  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3double\
     文件         803  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3double\DTreeUtil.class
     文件        8124  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3double\ID3.class
     文件         726  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3double\SequenceComparator.class
     文件         513  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3double\TreeNode.class
     目录           0  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3three\
     文件        9324  2017-04-17 20:49  DecisionTree\bin\com\decisionTree\ID3three\ID3.class
     文件         822  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3three\Maxgain.class
     文件         733  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3three\Point.class
     文件        2319  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3three\TheMath.class
     文件        3061  2017-04-17 19:39  DecisionTree\bin\com\decisionTree\ID3three\TreeNode.class
     目录           0  2017-03-17 19:23  DecisionTree\src\
     目录           0  2017-03-17 19:23  DecisionTree\src\com\
     目录           0  2017-03-18 14:35  DecisionTree\src\com\decisionTree\
............此处省略24个文件信息

评论

共有 条评论