-
Notifications
You must be signed in to change notification settings - Fork 0
/
classifierevaluator.cpp
77 lines (69 loc) · 1.36 KB
/
classifierevaluator.cpp
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
#include "classifierevaluator.h"
using namespace std;
ClassifierEvaluator::ClassifierEvaluator(Classifier& classifier,const InstancePool& trainingPool, const InstancePool& testPool)
{ //kataskeyastis tis classifierevaluator
tpos=0;
tneg=0;
fpos=0;
fneg=0;
total=0;
classifier.train(trainingPool);
this->total=testPool.getNumberOfInstances();
for (unsigned i=0; i<total; i++) //Ypologizontai ta stoixeia pou xreiazontai gia ta accuracy recall precision
{
if(testPool[i].getCategory())
{
if(classifier.classify(testPool[i]))
{
this->tpos++;
}
else
{
this->fneg++;
}
}
else
{
if(classifier.classify(testPool[i]))
{
this->fpos++;
}
else
{
this->tneg++;
}
}
}
}
float ClassifierEvaluator::getAccuracy() const //me8odos ypologismou accuracy
{
float a = 0.0;
a = ((float)(this->tpos + this->tneg) / this->total );
return a;
}
float ClassifierEvaluator::getPrecision() const // me8odos ypologismou precision
{
float a = 0.0;
if (((float)tpos + (float)fpos)!=0)
{
a = (float)tpos / ((float)tpos + (float)fpos);
return a;
}
else
{
return a;
}
}
float ClassifierEvaluator::getRecall() const //me8odos ypologismou recall
{
float a = 0.0;
if (((float)(this->tpos + this->fneg))!=0)
{
a = ((float)this->tpos / (float)(this->tpos + this->fneg));
return a;
}
else
{
return a;
}
}