In [12]:
def f1(precision,recall):
    if precision == 0.0 and recall == 0.0:
        return 0.0
    else:
        return 2 * float(precision)* float(recall) / ( precision+recall )

In [13]:
f1(0.31,0.76)


Out[13]:
0.44037383177570094

In [14]:
f1(0.64,0.38)


Out[14]:
0.4768627450980392

In [15]:
f1(0.39,0.16)


Out[15]:
0.2269090909090909

In [16]:
f1(0.22,0.18)


Out[16]:
0.19799999999999998

In [17]:
f1(0.11,0.39)


Out[17]:
0.1716

In [32]:
f1(1,1/2)


Out[32]:
0.6666666666666666

AP and MAP


In [ ]:
import numpy as np

In [ ]:
lst = []

In [ ]:
lst.append(np.array([1,2,3]))

In [ ]:
lst.append(np.array([4,4,4]))

In [ ]:
matrix = np.vstack(lst)

In [ ]:
matrix

In [ ]:
matrix.sum(axis=1)

In [ ]:
arr = np.array([1,2,3]).reshape(1,-1)

In [ ]:
np.sum(arr,axis=1)

In [ ]:
np.argsort(arr,axis=1)

In [ ]:
np.array([1,1]).shape

In [ ]:
original_y_true = np.array([[0.,1.],[1.,1.]]);original_y_true

In [ ]:
original_y_true.shape

In [ ]:
original_y_score = np.array([[0.,0.4],[0.9,0.1]]);original_y_score

In [ ]:
score_indices_top_k = np.array([[0,0],[0,0]]);score_indices_top_k

In [ ]:
row_indices_to_select = [i for i in range(original_y_true.shape[0])];row_indices_to_select

In [ ]:
column_indices_to_select = score_indices_top_k.T

In [ ]:
out = original_y_true[row_indices_to_select,column_indices_to_select];out

In [ ]:
out.shape

In [ ]:
arr1 = np.array([[0.5]])

In [ ]:
arr2 = np.array([[1.0]])

In [ ]:
lst = []
lst.append(arr1)
lst.append(arr2)

In [ ]:
np.vstack(lst)

In [ ]: