-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccuracyEvaluator.java
More file actions
41 lines (28 loc) · 1004 Bytes
/
AccuracyEvaluator.java
File metadata and controls
41 lines (28 loc) · 1004 Bytes
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
39
40
41
import java.util.List;
public class AccuracyEvaluator extends Evaluator {
@Override
public double evaluate(List<Instance> instances, Predictor predictor) {
double correct_number = 0;
for (Instance instance : instances) {
if (instance.getLabel() instanceof ClassificationLabel) {
ClassificationLabel label = (ClassificationLabel) instance
.getLabel();
ClassificationLabel prediction = (ClassificationLabel) predictor
.predict(instance);
if (instance.getLabel() != null) {
if (label.equals(prediction)) {
correct_number++;
}
}
} else if (instance.getLabel() instanceof RegressionLabel) {
RegressionLabel label = (RegressionLabel) instance.getLabel();
RegressionLabel prediction = (RegressionLabel) predictor
.predict(instance);
correct_number += Math.abs(prediction.getLabel()
- label.getLabel());
}
}
System.out.println(correct_number / instances.size());
return correct_number / instances.size();
}
}