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])

saveXLSX(output, 'tensor_dl_2classes_gc.xlsx')
Ejemplo n.º 2
0
                        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])

saveXLSX(output, 'tensor_mlp_2classes_bcw.xlsx')
                        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)

                        confMatrix = confusion_matrix(y_test, y_hat).tolist()

                        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)

                        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()

                        score_u = getScore('U', y_test, y_score)
                        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, 'tensor_dl_3classes_tmp.xlsx')
                    y_hat = np.argmax(y_score, axis=1)
                    y_test = np.argmax(y_test, axis=1)

                    confMatrix = confusion_matrix(y_test, y_hat).tolist()

                    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)

                    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()

                    score_u = getScore('U', y_test, y_score)
                    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, 'tensor_mlp_3classes_tmp.xlsx')
                                       })
                        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
                        ])

saveXLSX(output, 'tensor_dl_2classes_gc.xlsx')