python - Tensorflow:制作 ROC 曲线和混淆矩阵

标签 python tensorflow tensorboard tensor

背景
我正在努力掌握 tensorflow 的使用。我目前正在担任培训师和测试员,虽然Python对我来说完全没有问题,但我不知道如何使用tensorflow为我的测试绘制混淆矩阵和ROC曲线。我想这可以很容易地完成。

<小时/>

测试代码
我更喜欢给出一个可重现的示例,但我不知道如何才能如此简单地创建一个模型,以便将其放在这里。因此,如果有不清楚的地方,请告诉我

 def test_neural_network(self, test_data, model_name, model_folder):
        x = tf.placeholder('float')
        y = tf.placeholder('float')
        prediction = self.__convolutional_neural_network(x)
        with tf.Session() as sess:
            sess.run(tf.initialize_all_variables())
            saver = tf.train.Saver()

            for epoch in range(self.hm_epochs):
                try:
                    saver.restore(sess,  model_folder + model_name + '.ckpt')
                except Exception as e:
                    print(str(e))

            correct = tf.equal(tf.argmax(prediction, 1), tf.argmax(y, 1))
            accuracy = tf.reduce_mean(tf.cast(correct, 'float'))

            test_data = np.load(test_data)
            features, labels = [],[]
            for item in test_data:
                data = item[0]
                id = item[1]
                features.append(data)
                labels.append(id)
            test_x = np.array(features)
            test_y = np.array(labels)
            print(test_x)
            print(test_y)
            print('Accuracy:', accuracy.eval({x: test_x, y: test_y}))

问题
有什么方法可以在混淆矩阵和 ROC 曲线中可视化此测试吗?请注意,我熟悉 Python,但仅粗略地了解 tensorflow ,因此将不胜感激。

最佳答案

我没有足够的代表发表评论,所以我会将其作为答案发布。我已经使用 Scikit-Learn 的混淆矩阵功能为我自己的神经网络生成误差矩阵,请参阅:Confusion Matrix

关于python - Tensorflow:制作 ROC 曲线和混淆矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49817131/

相关文章:

python - 如何在python中将telnet输出日志保存到文本文件

python - 简单的单层神经网络

python - 安装CUDA工具包和cuDNN后Tensorflow不识别GPU

tensorflow - 喀拉斯CNN : Multi Label Classification of Images

python - Tensorboard 上的多个事件文件

python - Tensorflow model.fit() 使用数据集生成器

python - 错误 "The parameter redirect_uri is required"

Python Gekko 参数估计 : too long computational time because of "Dynamic Init C"

ubuntu - TensorBoard 无法绑定(bind)到端口 6006,它已经在使用中

numpy - Tensorflow - Tensorboard Event Accumulator 从 TensorEvent 获取 Tensor