【发布时间】:2017-08-24 19:25:25
【问题描述】:
我正在使用 Java 中的 WEKA 进行数据挖掘项目,说明说我必须为数据集中的每个属性创建一个 Attribute 对象并将它们添加到 FastVector。我尝试查看 API,但我认为我做得不对,有人可以告诉我正确的方法。我正在使用 iris.arff 文件
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instances;
import weka.core.converters.ArffSaver;
public class StartWeka {
public static void main(String[]args)throws Exception{
Instances dataset = new Instances(new BufferedReader(new FileReader("C:/Users/Student/workspace/Data Mining/src/iris.arff.txt")));
Instances train = new Instances(dataset);
train.setClassIndex(train.numAttributes()-1);
System.out.println(dataset.toSummaryString());
Attribute a1 = new Attribute("sepallength", 0);
Attribute a2 = new Attribute("sepalwidth", 1);
Attribute a3 = new Attribute("petalwidth", 2);
FastVector attrs = new FastVector();
attrs.addElement(a1);
}
}
【问题讨论】: