-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMajorityEvaluator.java
More file actions
38 lines (33 loc) · 1.06 KB
/
MajorityEvaluator.java
File metadata and controls
38 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package cs475;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Iterator;
import java.math.*;
public class MajorityEvaluator extends Evaluator {
private double evaValue = 0.0;
public double evaluate(List<Instance> instances, Predictor predictor){
int correct = 0;
int total = 0;
ClassificationLabel label = (ClassificationLabel)predictor.getLabel();
Iterator<Instance> it = instances.iterator();
while(it.hasNext()){
total = total + 1;
Instance i = it.next();
ClassificationLabel realLabel = (ClassificationLabel)i.getLabel();
if(realLabel == null){
break;
}
if (realLabel.getLabelValue() == label.getLabelValue()){
correct = correct+1;
}
}
// System.out.println(correct);
// System.out.println(total);
this.evaValue = ((double)correct / total);
return evaValue;
}
}