I would like some help on figuring out how to store values from an if-else statement into a variable.
My aim is to store the values from an .arff file of the predicted results, and comparing these predicted results to the win-draw-loss class values from the dataset. Because the predicted results are double, I convert these into win-draw-loss on the System.out.println() output. However, I wish to store these values when converted into the println() function into a variable, though I'm not sure howto.
Here's my script:
public class ForClassifier {
public static void main(String[] args) throws Exception {
String train1 = "C:/Users/Emil/Downloads/Week 1/Arsenal_TRAIN.arff";
Instances train = DatasetLoading.loadData(train1);
//train data
train.setClassIndex(train.numAttributes()-1);
Classifier Model = (Classifier)new NaiveBayes();
Model.buildClassifier(test);
for (int i = 0; i < train.numInstances(); i++)
{
String trueClassLabel;
trueClassLabel = train.instance(i).toString(train.classIndex());
double predicted = Model.classifyInstance(train.get(i));
if(predicted == 0.0) {
System.out.println("Loss" + "\t"+trueClassLabel);
}else if (predicted == 1.0){
System.out.println("Draw"+ "\t"+trueClassLabel);
}else if(predicted == 2.0) {
System.out.println("Win"+ "\t"+trueClassLabel);
}
}
I get the output which Is what I want, however, is there a way to store the output from predicted as when the value is equal to 0, store it as loss, then 1 as draw and 2 as win rather then printing out the function.
so that I can print out the variable as opposed to going through all the else-if statements?
Aucun commentaire:
Enregistrer un commentaire