I'm frustrated right now with Weka but mostly with my inability to understand what I'm doing wrong. I sent the following message to the Weka maillist:
Hi, I feel kind of embarrassed asking for help on what appears to be a super simple problem, but I've looked everywhere for answers and I'm a total newbie to both Weka and ML. I'm trying to use a MultilayerPerceptron to classify instances after I've trained it, but MultilayerPerceptron.evaluateModel() throws the exception, "No input instance format defined". I'm using the weather.arff file that is distributed with Weka as both the training and the test set (is that the problem?). Should I be filtering the data first?
Here's the code:
package classifier;
import weka.core.converters.*;
import weka.core.Instances;
import weka.core.Instance;
import java.io.File;
import java.io.IOException;
import weka.classifiers.Evaluation;
import java.util.Random;
import weka.classifiers.functions.MultilayerPerceptron;
import weka.core.FastVector;
import weka.core.Attribute;
import weka.gui.beans.DataSink;
import weka.core.converters.ArffSaver;
import weka.filters.AllFilter;
import weka.filters.Filter;
public class Main {
public static void main(String[] args) {
ArffLoader trainingloader = new ArffLoader();
ArffLoader testloader = new ArffLoader();
MultilayerPerceptron classifier = new MultilayerPerceptron();
Evaluation mevaluation;
Instances trainingData;
Instances testData;
File trainingFile = new File("D:\\ProgramFiles2\\Weka-3-6\\data\\weather.arff");
File testFile = new File("D:\\ProgramFiles2\\Weka-3-6\\data\\weather.arff");
try {
// Load the training data from the ARFF file
// Load the test data from the ARFF file
trainingloader.setFile(trainingFile);
testloader.setFile(testFile);
} catch (IOException e) {
System.out.println("IOException e39ge: " + e.getMessage());
}
try {
// Write the contents of the training data to an Instances object
trainingData = trainingloader.getDataSet();
testData = testloader.getDataSet();
System.out.println("\nContents of training data...:\n\n" + trainingData.toString());
System.out.println("\nContents of test data...:\n\n" + testData.toString());
try {
// Indicate the class attribute in the training data
trainingData.setClassIndex(trainingData.numAttributes() - 1);
testData.setClassIndex(trainingData.numAttributes() - 1);
// Evaluate the classifier
mevaluation = new Evaluation(trainingData);
mevaluation.evaluateModel(classifier, testData);
System.out.println(mevaluation.toSummaryString("\nResults of evaluation\n\n", false));
} catch (Exception e) {
System.out.println("Exception : " + e.getMessage());
}
} catch (Exception e) {
System.out.println("Exception : " + e.getMessage());
}
}
}
And here's a screenshot of the results (click to view a larger version):
Labels: metacreation, motion research