-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.R
53 lines (45 loc) · 1.53 KB
/
metrics.R
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
recall_m = function(y_true, y_pred) {
true_positives = k_sum(k_round(k_clip(y_true * y_pred, 0, 1)))
possible_positives = k_sum(k_round(k_clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + k_epsilon())
return(recall)
}
precision_m = function(y_true, y_pred) {
true_positives = k_sum(k_round(k_clip(y_true * y_pred, 0, 1)))
predicted_positives = k_sum(k_round(k_clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + k_epsilon())
return(precision)
}
f1_m = function(y_true, y_pred) {
precision = precision_m(y_true, y_pred)
recall = recall_m(y_true, y_pred)
return(2*((precision*recall)/(precision+recall+k_epsilon())) )
}
# recall_m = function(y_true, y_pred) {
# true_positives = k_sum(k_round(k_clip(k_dot(y_true, y_pred), 0, 1)))
# possible_positives = k_sum(k_round(k_clip(y_true, 0, 1)))
# recall = true_positives / (possible_positives + k_epsilon())
# return(recall)
# }
#
# precision_m = function(y_true, y_pred) {
# true_positives = k_sum(k_round(k_clip(k_dot(y_true, y_pred), 0, 1)))
# predicted_positives = k_sum(k_round(k_clip(y_pred, 0, 1)))
# precision = true_positives / (predicted_positives + k_epsilon())
# return(precision)
# }
#
#
#
# f1_metric <- custom_metric("f1", f1_m)
#
# f1_m = function(y_true, y_pred) {
# y_true = k_eval(y_true)
# print(y_true)
# y_pred = k_eval(y_pred)
# print(y_pred)
# f1_score = MLmetrics::F1_Score(y_true=y_true, y_pred=y_pred, positive="1")
# print(f1_score)
# return(k_constant(f1_score))
# }
#