I tried to find recall but type error occur
import pandas as pd
y_test = {'o1': [0,1,0,1],'o2': [1,1,0,1],'o3':[0,0,1,1]}
y_test = pd.DataFrame (y_test)
y_pred = {'o1': [1,1,0,1],'o2': [1,0,0,1],'o3':[1,0,1,1]}
y_pred = pd.DataFrame (y_pred)
y_pred = y_pred.to_numpy()
def precision(y_test, y_pred):
i = set(y_test).intersection(y_pred)
len1 = len(y_pred)
if len1 == 0:
return 0
else:
return len(i) / len1
print("recall of Binary Relevance Classifier: " + str(precision(y_test, y_pred)))
This code shown an error: actually i try to find recall for multi label classification error details iven below
TypeError Traceback (most recent call last)
<ipython-input-41-8f3ca706a8e6> in <module>
16 return len(i) / len1
17
---> 18 print("recall of Binary Relevance Classifier: " + str(precision(y_test, y_pred)))
<ipython-input-41-8f3ca706a8e6> in precision(y_test, y_pred)
9
10 def precision(y_test, y_pred):
---> 11 i = set(y_test).intersection(y_pred)
12 len1 = len(y_pred)
13 if len1 == 0:
TypeError: unhashable type: 'numpy.ndarray'