ประเมินประสิทธิภาพโมเดล CNN ที่ฝึกแล้ว ด้วย model.evaluate() และวาดกราฟ accuracy
โค้ดตัวอย่าง
print("วาดกราฟ Accuracy ต่อ Epoch...")
plt.plot(history.history['accuracy'], label='accuracy')
plt.plot(history.history['val_accuracy'], label='val_accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.ylim([0.5, 1])
plt.legend(loc='lower right')
print("กำลังประเมินโมเดล...")
test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)
print("ความแม่นยำของโมเดล:", test_acc)
ผลลัพธ์
วาดกราฟ Accuracy ต่อ Epoch...
กำลังประเมินโมเดล...
313/313 - 3s - loss: 0.8884 - accuracy: 0.7053
ความแม่นยำของโมเดล: 0.705299973487854

คำอธิบาย
history.history['accuracy']และval_accuracy: ข้อมูล accuracy ทุก epoch จากการฝึกmodel.evaluate(): คำนวณ loss และ metrics บน test set (ข้อมูลที่ไม่เคยเห็น)- Test accuracy: 70.5% - ประสิทธิภาพบนข้อมูลทดสอบ
- กราฟแสดง training accuracy สูงขึ้นเรื่อยๆ (เกือบ 100%) แต่ validation accuracy คงที่ ~70% -> Overfitting
- เทคนิคแก้ overfitting: Data Augmentation, Dropout, Regularization