Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

การสร้างกราฟแสดง Accuracy และ Loss ต่อเวลา บน IMDB ด้วย TensorFlow


บทนำ

TensorFlow เฟรมเวิร์ก ML จาก Google โค้ดเปิด ใช้กับ Python ใช้ในงานวิจัยและการผลิต

ชุดข้อมูล IMDB

รีวิวหนัง 50,000+ เรื่อง ใช้กับ NLP

ตัวอย่าง: พล็อต Loss ต่อ Epochs

history_dict = history.history
history_dict.keys()

acc = history_dict['binary_accuracy']
val_acc = history_dict['val_binary_accuracy']
loss = history_dict['loss']
val_loss = history_dict['val_loss']

epochs = range(1, len(acc) + 1)

plt.plot(epochs, loss, 'ro', label='Training loss')
plt.plot(epochs, val_loss, 'b', label='Validation loss')
plt.title('Training and validation loss with respect to time')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()

ที่มาโค้ด: TensorFlow Text Classification Tutorial

ผลลัพธ์

การสร้างกราฟแสดง Accuracy และ Loss ต่อเวลา บน IMDB ด้วย TensorFlow

คำอธิบาย

  • หลัง Fit โมเดลแล้ว เปรียบเทียบค่าจริงและทำนาย
  • ใช้ matplotlib พล็อต Loss ระหว่าง Training และ Validation
  • แสดงตามจำนวน Epochs (ขั้นตอนการฝึก)