-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate.jl
65 lines (60 loc) · 1.7 KB
/
evaluate.jl
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
using DataFrames
function evaluate(w, b, df, trainORtest, measures, modelName, err, objective)
n = size(df,1)
y = df[:,16]
x = df[:,1:15]
p = size(x,2)
accuracyVal = accuracy(n, p, w, b, x, y, measures)
precisionVal = precision(n, p, w, b, x, y, measures)
recallVal = recall(n, p, w, b, x, y, measures)
auc(n, p, w, b, x, y, measures, trainORtest, modelName)
push!(measures,[modelName,trainORtest,err,accuracyVal,precisionVal,recallVal, objective])
return measures
end
function accuracy(n, p, w, b, x, y, measures)
correct = 0
for i in 1:n
if y[i]*(sum(w[j] * x[i,j] for j=1:p) - b) > 0
correct = correct + 1
end
end
return correct/n
end
function precision(n, p, w, b, x, y, measures)
tp = 0
fp = 0
for i in 1:n
if y[i]*(sum(w[j] * x[i,j] for j=1:p) - b) > 0 && y[i] > 0
tp = tp + 1
end
if y[i]*(sum(w[j] * x[i,j] for j=1:p) - b) <= 0 && y[i] < 0
fp = fp + 1
end
end
return tp/(tp+fp)
end
function recall(n, p, w, b, x, y, measures)
tp = 0
fn = 0
for i in 1:n
if y[i]*(sum(w[j] * x[i,j] for j=1:p) - b) > 0 && y[i] > 0
tp = tp + 1
end
if y[i]*(sum(w[j] * x[i,j] for j=1:p) - b) <= 0 && y[i] > 0
fn = fn + 1
end
end
return tp/(tp+fn)
end
function auc(n, p, w, b, x, y, measures, trainORtest, modelName)
prediction = zeros(n)
for i in 1:n
if (sum(w[j] * x[i,j] for j=1:p) - b) < 0
prediction[i] = -1
else
prediction[i] = 1
end
end
auc = DataFrame( prediction = prediction, y = y)
writetable("auc_$trainORtest$modelName.csv",auc)
end