diff --git a/src/test/java/org/wlld/LangTest.java b/src/test/java/org/wlld/LangTest.java index 4af2699..c475ab5 100644 --- a/src/test/java/org/wlld/LangTest.java +++ b/src/test/java/org/wlld/LangTest.java @@ -3,8 +3,13 @@ package org.wlld; import org.wlld.naturalLanguage.IOConst; import org.wlld.naturalLanguage.Talk; import org.wlld.naturalLanguage.TemplateReader; +import org.wlld.randomForest.DataTable; +import org.wlld.randomForest.RandomForest; +import java.util.HashSet; import java.util.List; +import java.util.Random; +import java.util.Set; /** * @author lidapeng @@ -13,7 +18,55 @@ import java.util.List; */ public class LangTest { public static void main(String[] args) throws Exception { - test(); + test1(); + } + + public static void test1() throws Exception { + Set column = new HashSet<>(); + column.add("math"); + column.add("eng"); + column.add("word"); + column.add("history"); + column.add("h1"); + column.add("h2"); + column.add("h3"); + column.add("h4"); + column.add("point"); + DataTable dataTable = new DataTable(column); + dataTable.setKey("point"); + RandomForest randomForest = new RandomForest(7); + randomForest.init(dataTable);//唤醒随机森林里的树木 + //创建实体类输入数据 + for (int i = 0; i < 100; i++) { + Student student = new Student(); + student.setEng(getPoint()); + student.setH1(getPoint()); + student.setH2(getPoint()); + student.setH3(getPoint()); + student.setH4(getPoint()); + student.setMath(getPoint()); + student.setWord(getPoint()); + student.setHistory(getPoint()); + student.setPoint(getPoint()); + randomForest.insert(student); + } + randomForest.study(); + //以上都是学习过程 + Student student = new Student(); + student.setEng(getPoint()); + student.setH1(getPoint()); + student.setH2(getPoint()); + student.setH3(getPoint()); + student.setH4(getPoint()); + student.setMath(getPoint()); + student.setWord(getPoint()); + student.setHistory(getPoint()); + int point = randomForest.forest(student); + System.out.println("当前学生成绩的综合评定是:" + point); + } + + private static int getPoint() { + return new Random().nextInt(3) + 1; } public static void test() throws Exception { diff --git a/src/test/java/org/wlld/MatrixTest.java b/src/test/java/org/wlld/MatrixTest.java index 23bbdcd..f301acf 100644 --- a/src/test/java/org/wlld/MatrixTest.java +++ b/src/test/java/org/wlld/MatrixTest.java @@ -39,8 +39,6 @@ public class MatrixTest { food.setSex(random.nextInt(cla)); food.setH1(random.nextInt(cla)); food.setH2(random.nextInt(cla)); -// System.out.println("index==" + i + ",height==" + food.getHeight() + -// ",weight==" + food.getWeight() + ",sex==" + food.getSex()); dataTable.insert(food); } Tree tree = new Tree(dataTable); diff --git a/src/test/java/org/wlld/Student.java b/src/test/java/org/wlld/Student.java new file mode 100644 index 0000000..c1c2d4d --- /dev/null +++ b/src/test/java/org/wlld/Student.java @@ -0,0 +1,90 @@ +package org.wlld; + +/** + * @author lidapeng + * @description + * @date 3:37 下午 2020/3/6 + */ +public class Student {//特征是离散值,所以实体类里所有的基础类别都是整型 + private int math; + private int eng; + private int word; + private int history; + private int h1; + private int h2; + private int h3; + private int h4; + private int point; + + public int getMath() { + return math; + } + + public void setMath(int math) { + this.math = math; + } + + public int getEng() { + return eng; + } + + public void setEng(int eng) { + this.eng = eng; + } + + public int getWord() { + return word; + } + + public void setWord(int word) { + this.word = word; + } + + public int getHistory() { + return history; + } + + public void setHistory(int history) { + this.history = history; + } + + public int getH1() { + return h1; + } + + public void setH1(int h1) { + this.h1 = h1; + } + + public int getH2() { + return h2; + } + + public void setH2(int h2) { + this.h2 = h2; + } + + public int getH3() { + return h3; + } + + public void setH3(int h3) { + this.h3 = h3; + } + + public int getH4() { + return h4; + } + + public void setH4(int h4) { + this.h4 = h4; + } + + public int getPoint() { + return point; + } + + public void setPoint(int point) { + this.point = point; + } +}