-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprecision.c
50 lines (42 loc) · 1.08 KB
/
precision.c
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
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
double calculatePrecision(double *yTrue, double *yPred, size_t size)
{
double tpSum = 0;
double fpSum = 0;
for (int i = 0; i < size; i++)
{
if (yTrue[i] == 1 & yPred[i] == 1)
{
tpSum += 1;
}
else if (yTrue[i] == 0 & yPred[i] == 1)
{
fpSum += 1;
}
};
return tpSum / (tpSum + fpSum);
}
int main()
{
// Init x
size_t size = 5;
double init_y1[] = {1, 0, 1, 1, 0, 1};
double init_y2[] = {1, 0, 1, 0, 0, 1};
double *y1 = (double *)malloc(size * sizeof(double));
double *y2 = (double *)malloc(size * sizeof(double));
for (int i = 0; i < size; i++)
{
y1[i] = init_y1[i];
y2[i] = init_y2[i];
}
printf("Vector y1 with size %zu.\n", size);
printVector(y1, size, 0);
printf("Vector y2 with size %zu.\n", size);
printVector(y2, size, 0);
// Calculate precision
double precision = calculatePrecision(y1, y2, size);
printf("Precision is %0.2f.\n", precision);
return 0;
}