I'm using a weka classifier a on a training set, but i'd like to scale it before building the model. The problem is that i don't know how to do it. Here is the code which builds the classifier and performs the prediction. Files in "trainPath" and "predictPath" are in arff format.
void classify(String trainPath, String predictPath) {
try {
DataSource trainData = new DataSource(trainPath);
Instances train = trainData.getDataSet();
if(train.classIndex() == -1)
train.setClassIndex(train.numAttributes() -1);
DataSource predictData = new DataSource(predictPath);
Instances predict = predictData.getDataSet();
if(predict.classIndex() == -1)
predict.setClassIndex(predict.numAttributes() -1);
Classifier cls = new LibSVM();
cls.buildClassifier(train);
Instances labeled = new Instances(predict);
for (int c=0; c<predict.numInstances(); c++) {
double clsLabel = cls.classifyInstance(predict.instance(c));
labeled.instance(c).setClassValue(clsLabel);
}
BufferedWriter bw = new BufferedWriter(new FileWriter("files/labeled.arff"));
bw.write(labeled.toString());
bw.newLine();
bw.flush();
bw.close();
} catch (Exception e) {e.printStackTrace();}
}
I know that in Libsvm exists the svm-scale function, but i don't know how to use it.