【草稿】
其中阴影方框代表分子,白色空白方框+阴影方框代表分子
其中Jaccard和F1比较容易出错。
分析sklearn的jaccard_score如下:
''' jaccard 测试''' from sklearn.metrics import jaccard_score, f1_score, hamming_loss, accuracy_score import numpy as np y_true = np.array([[0, 1, 0, 1, 0],[0, 0, 1, 0, 0],[1, 0, 0, 0 ,1],]) y_pred = np.array([[1, 0, 0, 0, 0],[0, 0, 1, 0 ,0],[1, 0, 0, 1, 1],]) j_macro = jaccard_score(y_true, y_pred, average='macro') j_sample = jaccard_score(y_true, y_pred, average='samples') j_micro = jaccard_score(y_true, y_pred, average='micro') ##### jaccard 算法 ###### xx= np.minimum(y_true, y_pred) intersection = np.sum(np.minimum(y_true, y_pred), axis=0) union = np.sum(np.maximum(y_true, y_pred), axis=0) jaccard_per_class = intersection / union macro_jaccard_score = np.mean(jaccard_per_class) macro_jaccard_score print('sklearn-jaccard-macro',j_macro) print('jaccard algorithm',macro_jaccard_score) # (1/2+0+1+0+1)/5=0.5 print('sklearn-jaccard-samples',j_sample) # (0+1+2/3)/3=5/9=0.55555 print('sklearn-jaccard-micro',j_micro) # 3/7=0.428571428
标签:multi,jaccard,pred,label,metrics,score,macro,np,true From: https://www.cnblogs.com/mancy-gogo/p/17368847.html