给定一个包含以下内容的文本文件(比如 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中阅读它们?