yy = [] pp = [] seq_pred_y_valid = np.zeros((_seq_pred_y_valid.shape[0], before_steps)) seq_pred_y_valid[np.where( _seq_pred_y_valid[:, :before_steps] > sur_thrld_valid)] = 1 early_correct = np.sum(seq_pred_y_valid == batch_y_valid, axis=0) yy.extend(batch_y_valid) pp.extend(seq_pred_y_valid) yy = np.asarray(yy) pp = np.asarray(pp) gt = np.logical_not(yy).astype(float) pr = np.logical_not(pp).astype(float) _precision, _recall, _F1 = prec_reca_F1(gt, pr) seq_corr_rate = early_correct / float(_seq_pred_y_valid.shape[0]) thrld_score[sur_thrld_valid] = np.mean(seq_corr_rate) best_thrld, acc_best_threshold = max(thrld_score.iteritems(), key=operator.itemgetter(1)) # print best_thrld, acc_best_threshold, seq_corr_rate # # exit(0) # best_thrld = 0.9505 # # print "-----", best_thrld yy = [] pp = []
x = [[0, 1, 1, 0], [1, 1, 1, 0], [0, 1, 1, 1], [0, 0, 1, 0], [0, 0, 1, 0]] y = [[1, 0, 1, 0], [0, 0, 0, 0], [0, 1, 1, 1], [1, 0, 1, 0], [1, 1, 0, 1]] x = np.array(x) y = np.array(y) print x print print print print y precision, recall, F1 = prec_reca_F1(x, y) print print print "precison: ", precision print print "recall: ", recall print print "F1: ", F1 print exit(0)