TensorFlow绘制loss/accuracy曲线

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TensorFlow 中,可以使用 tf.math.confusion_matrix() 函数来生成混淆矩阵。ROC曲线的生成可以使用 sklearn.metrics中的roc_curve()函数。 下面是一个简单的示例代码: ```python import tensorflow as tf from sklearn.metrics import roc_curve import matplotlib.pyplot as plt # 加载数据集并进行预处理 (x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar10.load_data() x_train = tf.keras.applications.resnet50.preprocess_input(x_train) x_test = tf.keras.applications.resnet50.preprocess_input(x_test) y_train = tf.keras.utils.to_categorical(y_train, 10) y_test = tf.keras.utils.to_categorical(y_test, 10) # 构建模型 model = tf.keras.applications.ResNet50(weights=None, classes=10) model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']) # 训练模型 model.fit(x_train, y_train, epochs=10, validation_data=(x_test, y_test)) # 生成混淆矩阵 y_pred = model.predict(x_test) cm = tf.math.confusion_matrix(tf.argmax(y_test, axis=1), tf.argmax(y_pred, axis=1)) # 绘制ROC曲线 fpr, tpr, _ = roc_curve(y_test.ravel(), y_pred.ravel()) plt.plot(fpr, tpr) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.title('ROC Curve') plt.show() ``` 这个示例代码中使用了 ResNet50 模型来进行图像分类,并使用了 CIFAR10 数据集。训练完模型后,使用 tf.math.confusion_matrix() 函数来生成混淆矩阵,然后使用 sklearn.metrics 中的 roc_curve() 函数来生成 ROC 曲线。最后使用 matplotlib 库来绘制 ROC 曲线
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值