-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerformance.java
More file actions
110 lines (104 loc) · 2.25 KB
/
Copy pathPerformance.java
File metadata and controls
110 lines (104 loc) · 2.25 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import java.math.BigDecimal;
public class Performance {
DataSet dataset;
int classIndex;
int[] result;
int[] actualclass;
Double numofcorrect;
Double numofwrong;
Double[] accuracy;
Double meanaccuracy;
Double variance = 0.0;
Double maxdiff=0.0;
int k;//k-fold cross validation
static int i;
Performance(int k)
{
this.k = k;
accuracy = new Double[k];
i=0;
}
Performance(DataSet dataset, int classIndex,int[] result)
{
this.dataset = dataset;
this.classIndex = classIndex;
this.result = result;
actualclass = new int[dataset.examples.size()];
for(int i=0;i<dataset.examples.size();i++)
{
actualclass[i] = dataset.examples.get(i).get(classIndex).intValue();
}
numofcorrect = 0.0;
numofwrong = 0.0;
for(int i=0;i<actualclass.length;i++)
{
if(actualclass[i]==result[i])
numofcorrect+=1;
else
numofwrong+=1;
}
}
String getStringAccuracy()
{
Double acc = numofcorrect/(numofwrong+numofcorrect);
String output = acc*100+"%";
return output;
}
Double getDoubleAccuracy()
{
return numofcorrect/(numofwrong+numofcorrect);
}
public String toString()
{
return "";
}
public void addAccuracy(Double d1)
{
if(i<k)
{
this.accuracy[i] = d1;
i++;
}
}
public Double getDoubleMeanAccuracy()
{
double temp=0;
for(int j=0;j<k;j++)
{
temp+=this.accuracy[j];
}
meanaccuracy = temp/k;
return temp/k;
}
public String getStringMeanAccuracy()
{
getDoubleMeanAccuracy();
for(int j=0;j<k;j++)
{
if(this.accuracy[j]-meanaccuracy>maxdiff)
maxdiff = this.accuracy[j]-meanaccuracy;
if(meanaccuracy-this.accuracy[j]>maxdiff)
maxdiff = meanaccuracy-this.accuracy[j];
//System.out.println(this.accuracy[j]);
}
BigDecimal bd = new BigDecimal(meanaccuracy*100);
BigDecimal maxbd = new BigDecimal(maxdiff*100);
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
maxbd = maxbd.setScale(2, BigDecimal.ROUND_HALF_UP);
return bd+"% ± "+maxbd+"%";
}
public Double getVariace()
{
double temp=0;
for(int j=0;j<k;j++)
{
temp=Math.pow(this.accuracy[j]-meanaccuracy, 2);
variance+=temp;
}
variance = variance/k;
BigDecimal va = new BigDecimal(variance);
//System.out.println(variance);
va = va.setScale(5, BigDecimal.ROUND_HALF_UP);
return va.doubleValue();
}
}