y_score = clf.predict_proba(X_test) y_hat = clf.predict(X_test) ys = [y_s[y_h] for y_s, y_h in zip(y_score, y_hat)] tmp = np.append(X_test, np.reshape(y_test, (1, y_test.shape[0])).T, axis=1) tmp = np.append(tmp, np.reshape(y_hat, (1, y_hat.shape[0])).T, axis=1) tmp = np.append(tmp, y_score, axis=1) tmp = np.append(tmp, np.asarray(ys), axis=1) output['data'] = [['X_' + str(i) for i in range(1, X_test.shape[1] + 1)] + ['y_label', 'y_hat', 'y_score', 'y_score', 'ys']] + \ tmp.tolist() acc = accuracy_score(y_hat, y_test) fpr, tpr, threshold = getScore('ROC', y_test, y_hat) score_auc = getScore('AUC', y_test, y_hat) output['score'].append([ lrt, lr, hu, ni, ii, acc, fpr[1], tpr[1], metrics.auc(fpr, tpr), score_auc, (endTime - startTime).seconds + (endTime - startTime).microseconds / 10**6 ]) saveXLSX(output, 'mlp_2classes_bcw.xlsx')
ys = [y_s[y_h-1] for y_s, y_h in zip(y_score, y_hat)] tmp = np.append(X_test, np.reshape(y_test, (1,y_test.shape[0])).T, axis=1) tmp = np.append(tmp, np.reshape(y_hat, (1,y_hat.shape[0])).T, axis=1) tmp = np.append(tmp, y_score, axis=1) tmp = np.append(tmp, np.asarray(ys), axis=1) output['data'] = [['X_' + str(i) for i in range(1, X_test.shape[1] + 1)] + ['y_label', 'y_hat', 'y_score_1', 'y_score_2', 'y_score_3', 'ys']] + \ tmp.tolist() acc = accuracy_score(y_hat, y_test) confMatrix = confusion_matrix(y_test, y_hat).tolist() # fpr, tpr, threshold = getScore('ROC', y_test, y_hat) # score_auc = getScore('AUC', y_test, y_hat) score_u = getScore('U', y_test, y_score) # score_u_s = getScore('U_S', y_test, ys) # score_u_m = getScore('U_MannWhitneyu', y_test, np.asarray(ys).T[0]) score_VUS_1 = getScore('VUS_1', y_test, y_hat) score_VUS_2 = getScore('VUS_2', y_test, y_score) output['score'].append( [lrt, lr, hu, ni, ii, acc, score_u, score_VUS_1, score_VUS_2] + confMatrix[0] + confMatrix[1] + confMatrix[2] + [(endTime - startTime).seconds + (endTime - startTime).microseconds / 10 ** 6]) saveXLSX(output, 'results/mlp_3classes_w.xlsx')
startTime = datetime.now() for i in range(ni): # print(i) batch_xs, batch_ys = X_train, y_train sess.run(train_step, feed_dict={x: batch_xs, yy_: batch_ys}) endTime = datetime.now() correct_prediction = tf.equal(tf.argmax(yy,1), tf.argmax(yy_,1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) y_score = sess.run(yy, feed_dict={x: X_test, yy_: y_test}) acc = sess.run(accuracy, feed_dict={x: X_test, yy_: y_test}) y_hat = np.argmax(y_score, axis=1) y_test = np.argmax(y_test, axis=1) fpr, tpr, threshold = getScore('ROC', y_test, y_hat) score_auc = getScore('AUC', y_test, y_hat) tmp = np.append(X_test, np.reshape(y_test, (1, y_test.shape[0])).T, axis=1) tmp = np.append(tmp, np.reshape(y_hat, (1, y_hat.shape[0])).T, axis=1) tmp = np.append(tmp, y_score, axis=1) # tmp = np.append(tmp, np.asarray(ys), axis=1) output['data'] = [['X_' + str(i) for i in range(1, X_test.shape[1] + 1)] + ['y_label', 'y_hat', 'y_score', 'y_score']] + \ tmp.tolist() output['score'].append( [lrt, lr, hu, ni, ii, acc, fpr[1], tpr[1], metrics.auc(fpr, tpr), score_auc, (endTime - startTime).seconds + ( endTime - startTime).microseconds / 10 ** 6])
axis=1) tmp = np.append(tmp, y_score, axis=1) tmp = np.append(tmp, np.asarray(ys), axis=1) output['data'] = [['X_' + str(i) for i in range(1, X_test.shape[1] + 1)] + ['y_label', 'y_hat', 'y_score_1', 'y_score_2', 'y_score_3', 'ys']] + \ tmp.tolist() acc = accuracy_score(y_hat, y_test) confMatrix = confusion_matrix(y_test, y_hat).tolist() # fpr, tpr, threshold = getScore('ROC', y_test, y_hat) # score_auc = getScore('AUC', y_test, y_hat) score_u = getScore('U', y_test, y_score) # score_u_s = getScore('U_S', y_test, ys) # score_u_m = getScore('U_MannWhitneyu', y_test, np.asarray(ys).T[0]) score_VUS_1 = getScore('VUS_1', y_test, y_hat) score_VUS_2 = getScore('VUS_2', y_test, y_score) output['score'].append( [ lrt, lr, hu, ni, ii, acc, score_u, score_VUS_1, score_VUS_2 ] + confMatrix[0] + confMatrix[1] + confMatrix[2] + [(endTime - startTime).seconds + (endTime - startTime).microseconds / 10**6]) saveXLSX(output, 'results/mlp_3classes_bs.xlsx')