Read training data from arff file:
public static Instances get_instances_from_arff() throws Exception {
BufferedReader breader = null;
breader = new BufferedReader( new FileReader(System.getProperty("user.dir")+"/src/weka_usage/exploration_tracks.arff") );
Instances training_data = new Instances(breader);
training_data.setClassIndex(training_data.numAttributes() -1);
breader.close();
return training_data;
}
Create new instance with new provided attributes:
public static Instance create_instance(double[] attr, Instances training_data){
// Create the instance
DenseInstance inst = new DenseInstance(4);
//Instance inst = new DenseInstance(4);
inst.setValue(0, attr[0]); //web
inst.setValue(1, attr[1]); //db
inst.setValue(2, attr[2]); //arrival rate
inst.setValue(3, attr[3]); // response time
inst.setDataset(training_data); // assosiate training data with instance to help in its classification
return inst;
}
build_classifier method:
public static AbstractClassifier build_classifier(String type, Instances data) throws Exception{
if(type == "RandomForest"){
RandomForest rF = new RandomForest();
rF.buildClassifier(data);
return rF;
}
else if(type == "MultilayerPerceptron"){
MultilayerPerceptron rF = new MultilayerPerceptron();
rF.buildClassifier(data);
return rF;
}
else if(type == "LinearRegression"){
LinearRegression rF = new LinearRegression();
rF.buildClassifier(data);
return rF;
}
else{
//GaussianProcesses is default
GaussianProcesses rF = new GaussianProcesses();
rF.buildClassifier(data);
return rF;
}
}
how to test a new instance entered by user and predict the class?