AUC
实现的有问题,只有部分可以运行,之后会显示超范围
def auc_calculate(labels, preds, n_bins=100):
postive_len = sum(labels)
negative_len = len(labels) - postive_len
total_case = postive_len * negative_len
pos_histogram = [0 for _ in range(n_bins)]
neg_histogram = [0 for _ in range(n_bins)]
bin_width = 1.0 / n_bins
for i in range(len(labels)):
nth_bin = int(preds[i] / bin_width)
if labels[i] == 1:
pos_histogram[nth_bin] += 1
else:
neg_histogram[nth_bin] += 1
accumulated_neg = 0
satisfied_pair = 0
for i in range(n_bins):
satisfied_pair += (pos_histogram[i] * accumulated_neg + pos_histogram[i] * neg_histogram[i] * 0.5)
accumulated_neg += neg_histogram[i]
return satisfied_pair / float(total_case)
def average_auc(labels,preds):
n, m = labels.shape
macro_auc = 0
valid_labels = 0
for i in range(n):
temp = auc_calculate(labels[i], preds[i])
macro_auc += temp
valid_labels += 1
macro_auc = macro_auc / valid_labels
return macro_auc
F1
Art
epoch: 0, Train Loss: 0.062766,Eval Loss: 0.063152, Eval Acc: 0.936848, Eval Pre: nan,Eval Recall: 0.000000,Eval f1: nan
epoch: 1, Train Loss: 0.058287,Eval Loss: 0.063152, Eval Acc: 0.936848, Eval Pre: nan,Eval Recall: 0.000000,Eval f1: nan
C:/Users/huoyifeng/Desktop/Multi-Label/masp-master/testboolean/MLBF(only mebf).py:346: RuntimeWarning: invalid value encountered in double_scalars
F1=(2PreRecall)/(Pre+Recall)
epoch: 2, Train Loss: 0.054962,Eval Loss: 0.060991, Eval Acc: 0.939009, Eval Pre: nan,Eval Recall: 0.039068,Eval f1: nan
epoch: 3, Train Loss: 0.051054,Eval Loss: 0.057846, Eval Acc: 0.942154, Eval Pre: nan,Eval Recall: 0.110558,Eval f1: nan
epoch: 4, Train Loss: 0.048249,Eval Loss: 0.056324, Eval Acc: 0.943676, Eval Pre: 0.763969,Eval Recall: 0.157961,Eval f1: nan
epoch: 5, Train Loss: 0.046158,Eval Loss: 0.055340, Eval Acc: 0.944660, Eval Pre: 0.756385,Eval Recall: 0.184826,Eval f1: 0.290217
epoch: 6, Train Loss: 0.044314,Eval Loss: 0.054918, Eval Acc: 0.945082, Eval Pre: 0.749427,Eval Recall: 0.199158,Eval f1: 0.308213
epoch: 7, Train Loss: 0.042882,Eval Loss: 0.054726, Eval Acc: 0.945274, Eval Pre: 0.737422,Eval Recall: 0.211373,Eval f1: 0.322137
epoch: 8, Train Loss: 0.041505,Eval Loss: 0.054751, Eval Acc: 0.945249, Eval Pre: 0.716988,Eval Recall: 0.222356,Eval f1: 0.333353
epoch: 9, Train Loss: 0.040178,Eval Loss: 0.054521, Eval Acc: 0.945479, Eval Pre: 0.725654,Eval Recall: 0.222619,Eval f1: 0.335112
epoch: 10, Train Loss: 0.039037,Eval Loss: 0.054624, Eval Acc: 0.945376, Eval Pre: 0.708862,Eval Recall: 0.232685,Eval f1: 0.344544
epoch: 11, Train Loss: 0.037844,Eval Loss: 0.054470, Eval Acc: 0.945530, Eval Pre: 0.706174,Eval Recall: 0.237207,Eval f1: 0.349409
epoch: 12, Train Loss: 0.036743,Eval Loss: 0.054483, Eval Acc: 0.945517, Eval Pre: 0.703172,Eval Recall: 0.240834,Eval f1: 0.353302
epoch: 13, Train Loss: 0.035644,Eval Loss: 0.054854, Eval Acc: 0.945146, Eval Pre: 0.680692,Eval Recall: 0.251744,Eval f1: 0.362243
epoch: 14, Train Loss: 0.034601,Eval Loss: 0.054675, Eval Acc: 0.945325, Eval Pre: 0.682283,Eval Recall: 0.255162,Eval f1: 0.366093
epoch: 15, Train Loss: 0.033531,Eval Loss: 0.055327, Eval Acc: 0.944673, Eval Pre: 0.663607,Eval Recall: 0.257369,Eval f1: 0.365745
epoch: 16, Train Loss: 0.032535,Eval Loss: 0.054726, Eval Acc: 0.945274, Eval Pre: 0.675952,Eval Recall: 0.259170,Eval f1: 0.369463
epoch: 17, Train Loss: 0.031529,Eval Loss: 0.055301, Eval Acc: 0.944699, Eval Pre: 0.661235,Eval Recall: 0.263359,Eval f1: 0.371112
epoch: 18, Train Loss: 0.030543,Eval Loss: 0.055749, Eval Acc: 0.944251, Eval Pre: 0.642784,Eval Recall: 0.273480,Eval f1: 0.378352
epoch: 19, Train Loss: 0.029578,Eval Loss: 0.055557, Eval Acc: 0.944443, Eval Pre: 0.647634,Eval Recall: 0.270267,Eval f1: 0.375880
epoch: 20, Train Loss: 0.028586,Eval Loss: 0.055864, Eval Acc: 0.944136, Eval Pre: 0.638633,Eval Recall: 0.273486,Eval f1: 0.377669
epoch: 21, Train Loss: 0.027666,Eval Loss: 0.056375, Eval Acc: 0.943625, Eval Pre: 0.625339,Eval Recall: 0.276153,Eval f1: 0.378011
epoch: 22, Train Loss: 0.026693,Eval Loss: 0.056452, Eval Acc: 0.943548, Eval Pre: 0.621033,Eval Recall: 0.280735,Eval f1: 0.381407
epoch: 23, Train Loss: 0.025764,Eval Loss: 0.056260, Eval Acc: 0.943740, Eval Pre: 0.629021,Eval Recall: 0.276195,Eval f1: 0.378506
epoch: 24, Train Loss: 0.024832,Eval Loss: 0.056657, Eval Acc: 0.943343, Eval Pre: 0.617031,Eval Recall: 0.281242,Eval f1: 0.380922
epoch: 25, Train Loss: 0.023927,Eval Loss: 0.056976, Eval Acc: 0.943024, Eval Pre: 0.609845,Eval Recall: 0.282389,Eval f1: 0.380651
epoch: 26, Train Loss: 0.023061,Eval Loss: 0.056900, Eval Acc: 0.943100, Eval Pre: 0.613523,Eval Recall: 0.277080,Eval f1: 0.376331
epoch: 27, Train Loss: 0.022211,Eval Loss: 0.057117, Eval Acc: 0.942883, Eval Pre: 0.609873,Eval Recall: 0.281521,Eval f1: 0.379629
epoch: 28, Train Loss: 0.021376,Eval Loss: 0.057219, Eval Acc: 0.942781, Eval Pre: 0.603997,Eval Recall: 0.284337,Eval f1: 0.381130
epoch: 29, Train Loss: 0.020552,Eval Loss: 0.057437, Eval Acc: 0.942563, Eval Pre: 0.600310,Eval Recall: 0.283662,Eval f1: 0.380017
yeast
epoch: 0, Train Loss: 0.096118,Eval Loss: 0.234016, Eval Acc: 0.765984, Eval Pre: 0.746408,Eval Recall: 0.350603,Eval f1: 0.476279
epoch: 1, Train Loss: 0.088896,Eval Loss: 0.229552, Eval Acc: 0.770448, Eval Pre: 0.752524,Eval Recall: 0.366622,Eval f1: 0.492091
epoch: 2, Train Loss: 0.087068,Eval Loss: 0.218955, Eval Acc: 0.781045, Eval Pre: 0.744825,Eval Recall: 0.427440,Eval f1: 0.541799
epoch: 3, Train Loss: 0.085554,Eval Loss: 0.216133, Eval Acc: 0.783867, Eval Pre: 0.723301,Eval Recall: 0.470557,Eval f1: 0.568768
epoch: 4, Train Loss: 0.084128,Eval Loss: 0.211643, Eval Acc: 0.788357, Eval Pre: 0.721192,Eval Recall: 0.498363,Eval f1: 0.588027
epoch: 5, Train Loss: 0.082942,Eval Loss: 0.214260, Eval Acc: 0.785740, Eval Pre: 0.732285,Eval Recall: 0.467582,Eval f1: 0.569137
epoch: 6, Train Loss: 0.082177,Eval Loss: 0.214517, Eval Acc: 0.785483, Eval Pre: 0.706353,Eval Recall: 0.507084,Eval f1: 0.588625
epoch: 7, Train Loss: 0.081642,Eval Loss: 0.210309, Eval Acc: 0.789691, Eval Pre: 0.719805,Eval Recall: 0.507582,Eval f1: 0.593703
epoch: 8, Train Loss: 0.081195,Eval Loss: 0.210771, Eval Acc: 0.789229, Eval Pre: 0.729333,Eval Recall: 0.491941,Eval f1: 0.585806
epoch: 9, Train Loss: 0.080267,Eval Loss: 0.209231, Eval Acc: 0.790769, Eval Pre: 0.730236,Eval Recall: 0.498918,Eval f1: 0.591064
epoch: 10, Train Loss: 0.080008,Eval Loss: 0.215184, Eval Acc: 0.784816, Eval Pre: 0.690865,Eval Recall: 0.532117,Eval f1: 0.599659
epoch: 11, Train Loss: 0.079641,Eval Loss: 0.207923, Eval Acc: 0.792077, Eval Pre: 0.701436,Eval Recall: 0.553210,Eval f1: 0.616932
epoch: 12, Train Loss: 0.079059,Eval Loss: 0.214337, Eval Acc: 0.785663, Eval Pre: 0.689949,Eval Recall: 0.539941,Eval f1: 0.604158
epoch: 13, Train Loss: 0.078938,Eval Loss: 0.210591, Eval Acc: 0.789409, Eval Pre: 0.702504,Eval Recall: 0.536318,Eval f1: 0.606520
epoch: 14, Train Loss: 0.078468,Eval Loss: 0.207204, Eval Acc: 0.792796, Eval Pre: 0.706189,Eval Recall: 0.549075,Eval f1: 0.616079
epoch: 15, Train Loss: 0.078002,Eval Loss: 0.207948, Eval Acc: 0.792052, Eval Pre: 0.711921,Eval Recall: 0.536236,Eval f1: 0.609906
epoch: 16, Train Loss: 0.077653,Eval Loss: 0.203510, Eval Acc: 0.796490, Eval Pre: 0.709410,Eval Recall: 0.562925,Eval f1: 0.626217
epoch: 17, Train Loss: 0.077385,Eval Loss: 0.203689, Eval Acc: 0.796311, Eval Pre: 0.705566,Eval Recall: 0.570066,Eval f1: 0.628932
epoch: 18, Train Loss: 0.077014,Eval Loss: 0.205255, Eval Acc: 0.794745, Eval Pre: 0.733091,Eval Recall: 0.514848,Eval f1: 0.603181
epoch: 19, Train Loss: 0.077058,Eval Loss: 0.203792, Eval Acc: 0.796208, Eval Pre: 0.701349,Eval Recall: 0.577773,Eval f1: 0.631956
epoch: 20, Train Loss: 0.076434,Eval Loss: 0.205793, Eval Acc: 0.794207, Eval Pre: 0.702066,Eval Recall: 0.564645,Eval f1: 0.624299
epoch: 21, Train Loss: 0.075951,Eval Loss: 0.205075, Eval Acc: 0.794925, Eval Pre: 0.691266,Eval Recall: 0.592542,Eval f1: 0.636462
epoch: 22, Train Loss: 0.076220,Eval Loss: 0.203741, Eval Acc: 0.796259, Eval Pre: 0.712806,Eval Recall: 0.555438,Eval f1: 0.622672
epoch: 23, Train Loss: 0.075397,Eval Loss: 0.204357, Eval Acc: 0.795643, Eval Pre: 0.696359,Eval Recall: 0.584820,Eval f1: 0.634222
epoch: 24, Train Loss: 0.074948,Eval Loss: 0.204562, Eval Acc: 0.795438, Eval Pre: 0.702495,Eval Recall: 0.571006,Eval f1: 0.628299
epoch: 25, Train Loss: 0.075121,Eval Loss: 0.204562, Eval Acc: 0.795438, Eval Pre: 0.696948,Eval Recall: 0.583382,Eval f1: 0.633184
epoch: 26, Train Loss: 0.074645,Eval Loss: 0.201149, Eval Acc: 0.798851, Eval Pre: 0.700425,Eval Recall: 0.596836,Eval f1: 0.642535
epoch: 27, Train Loss: 0.074692,Eval Loss: 0.203279, Eval Acc: 0.796721, Eval Pre: 0.693611,Eval Recall: 0.598108,Eval f1: 0.640575
epoch: 28, Train Loss: 0.074016,Eval Loss: 0.202612, Eval Acc: 0.797388, Eval Pre: 0.699183,Eval Recall: 0.589699,Eval f1: 0.638015
epoch: 29, Train Loss: 0.073713,Eval Loss: 0.202894, Eval Acc: 0.797106, Eval Pre: 0.689926,Eval Recall: 0.608796,Eval f1: 0.645190