0
我在使用Java中的WEKA開展數據挖掘項目並且說明中說我必須爲數據集中的每個屬性創建一個Attribute對象並將它們添加到FastVector。我試圖看看API,但我認爲我沒有做到這一點,有人可以告訴我正確的做法。我使用的iris.arff文件如何在Weka中創建屬性
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 {
\t public static void main(String[]args)throws Exception{
\t \t
\t \t Instances dataset = new Instances(new BufferedReader(new FileReader("C:/Users/Student/workspace/Data Mining/src/iris.arff.txt")));
\t \t
\t \t Instances train = new Instances(dataset);
\t \t train.setClassIndex(train.numAttributes()-1);
\t \t
\t \t System.out.println(dataset.toSummaryString());
\t \t
\t \t Attribute a1 = new Attribute("sepallength", 0);
Attribute a2 = new Attribute("sepalwidth", 1);
Attribute a3 = new Attribute("petalwidth", 2);
FastVector attrs = new FastVector();
\t \t attrs.addElement(a1);
\t }
}