我尝试使用Tensorflow找到模型的测试AUC,但作为一个完整的初学者,我无法让它工作 . 这是我的代码:

非常感谢您的帮助!

def训练(x_train,y_train,x_test,y_test):

prediction = NN(x)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=prediction,labels=y))
optimizer = tf.train.AdamOptimizer().minimize(cost) # Stochastic gradient descent, learning rate default 0.001

# Cycles of feedforward +  backpropagation
epochs = 1

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())

    for epoch in range(epochs):
        epoch_loss = 0 
        batches = int(train_x.shape[0]/batch_size)# Number of batches

        # Partitioning data into batches
        x_batches = np.array_split(x_train, total_batch)
        y_batches = np.array_split(y_train, total_batch)

        # Looping over each training batch
        for _ in range(batches):
            epoch_x,epoch_y = x_batches[i], y_batches[i]
            _, c = sess.run([optimizer,cost], feed_dict={x:epoch_x, y:epoch_y})
            epoch_loss += c
        print('Epoch', epoch, 'completed out of', epochs, 'loss:', epoch_loss)

        correct = tf.equal(tf.argmax(prediction,1),tf.argmax(y,1))
        accuracy = tf.reduce_mean(tf.cast(correct,'float'))
        print('Accuracy:', accuracy.eval({x:x_test, y:y_test}))

    # Save final predictions 
    predict = tf.nn.softmax(prediction, dim=-1, name=None)
    predictions1 = sess.run(predict, feed_dict={x:x_test})
    out = predictions1
    print(predictions1[1:10,0])

    # AUC

    AUC = tf.metrics.auc(
    labels=y,
    predictions=prediction,
    weights=None,
    num_thresholds=200,
    metrics_collections=None,
    updates_collections=None,
    curve='ROC',
    name=None,
    summation_method='trapezoidal'
    )
    AUC1 = sess.run(AUC, feed_dict = {x:x_test, y:y_test})