-
Notifications
You must be signed in to change notification settings - Fork 3
/
Measures.java
executable file
·78 lines (70 loc) · 2.03 KB
/
Measures.java
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.HashMap;
public class Measures {
double[] targets;
double[] predictions;
final String targetValue;
public Measures(HashMap<String, String> targets, HashMap<String, String> predictions, String targetValue){
int index = 0;
this.targets = new double[targets.keySet().size()];
this.predictions = new double[targets.keySet().size()];
this.targetValue = targetValue;
for(String assignment : targets.keySet()){
if(targetValue.equals("NA!")){
this.targets[index] = Double.parseDouble(targets.get(assignment));
}else{
this.targets[index] = (targets.get(assignment).equals(targetValue) ? 1.0 : 0.0);
}
this.predictions[index] = Double.parseDouble(predictions.get(assignment));
index++;
}
}
public double accuracy(double boundary){
double correct = 0.0;
for(int i = 0; i < targets.length; i++){
if(targets[i] == 1 && predictions[i] >= boundary)
correct++;
else if(targets[i] == 0 && predictions[i] < boundary)
correct++;
}
return correct / targets.length;
}
public double MAE(){
double mae = 0.0;
for(int i = 0; i < targets.length; i++){
if(targets[i] == 1)
mae += 1 - predictions[i];
else if(targets[i] == 0)
mae += predictions[i];
}
return mae / targets.length;
}
private double MSE_Cont(){
double mse = 0;
for(int i = 0; i < targets.length; i++){
mse += Math.pow(predictions[i] - targets[i], 2);
}
return mse / targets.length;
}
public double MSE(){
if(this.targetValue.equals("NA!"))
return MSE_Cont();
double mse = 0.0;
for(int i = 0; i < targets.length; i++){
if(targets[i] == 1)
mse += Math.pow(1 - predictions[i], 2);
else if(targets[i] == 0)
mse += Math.pow(predictions[i], 2);
}
return mse / targets.length;
}
public double ACLL(){
double acll = 0;
for(int i = 0; i < targets.length; i++){
if(targets[i] == 1)
acll += (Math.log10(predictions[i]) / Math.log10(2.0));
else if(targets[i] == 0)
acll += (Math.log10(1 - predictions[i]) / Math.log10(2.0));
}
return acll / targets.length;
}
}