-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.py
44 lines (36 loc) · 1.29 KB
/
metrics.py
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
import numpy
from scipy.stats import gmean
def income_by_filter(actual_delta, predicted, filter = lambda x: True):
indexes = predicted.apply(filter)
to_buy = actual_delta[indexes]
if len(to_buy) == 0:
return 0
return numpy.mean(to_buy)
def incom_not_weighted(actual_delta, predicted, threshold=30):
actual_delta = numpy.array(actual_delta)
predicted = numpy.array(predicted)
indexes = numpy.where(predicted > threshold)
to_buy = actual_delta[indexes]
if len(to_buy) < 3:
return None
quantities = numpy.array([1./len(to_buy) for i in to_buy])
income = sum(to_buy * quantities)
return income
# if len(to_buy) < 3:
# return None
# return (gmean((to_buy / 100) + 1) - 1) * 100
# return numpy.mean(to_buy)
def incom_reverse_weight(actual_delta, predicted, threshold=30):
actual_delta = numpy.array(actual_delta)
predicted = numpy.array(predicted)
indexes = numpy.where(predicted > threshold)
to_buy = actual_delta[indexes]
weights = 100 - to_buy
weights = weights / sum(weights)
if len(to_buy) < 3:
return None
return (gmean((to_buy / 100) + 1) - 1) * 100
# return numpy.mean(to_buy)
if __name__ == "__main__":
income = incom_not_weighted([10,20,30,40], [25,34,31,2])
print(income)