有没有办法从文本文件中读取J48 Pruned Tree?

时间:2017-06-30 12:44:21

标签: java weka j48

给定一个包含以下内容的文本文件(比如weather.txt):

outlook = sunny
|   humidity <= 75: yes (2.0)
|   humidity > 75: no (3.0)
outlook = overcast: yes (4.0)
outlook = rainy
|   windy = TRUE: no (2.0)
|   windy = FALSE: yes (3.0)

Java中有没有办法将此文本作为J48对象阅读。

目前我有一个数据文件“data.txt”(采用arff格式):

@relation weather

@attribute outlook {sunny, overcast, rainy}
@attribute temperature numeric
@attribute humidity numeric
@attribute windy {TRUE, FALSE}
@attribute play {yes, no}

@data
sunny,85,85,FALSE,no
sunny,80,90,TRUE,no
overcast,83,86,FALSE,yes
rainy,70,96,FALSE,yes
rainy,68,80,FALSE,yes
rainy,65,70,TRUE,no
overcast,64,65,TRUE,yes
sunny,72,95,FALSE,no
sunny,69,70,FALSE,yes
rainy,75,80,FALSE,yes
sunny,75,70,TRUE,yes
overcast,72,90,TRUE,yes
overcast,81,75,FALSE,yes
rainy,71,91,TRUE,no

我当前的代码是(如下所示)打印上面的树:

    J48 cls = new J48();
    Instances inst = new Instances(new BufferedReader(new FileReader("data.txt")));
    inst.setClassIndex(inst.numAttributes() - 1);
    cls.buildClassifier(inst);

    weka.core.SerializationHelper.write("j48.model", cls);

    J48 cls2 = (J48) weka.core.SerializationHelper.read("j48.model");
    System.out.println(cls2);

我的目标是将这些树保存在文本文件中。并阅读它们。如何在java中阅读它们?

0 个答案:

没有答案