เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การประเมินความแม่นยำของโมเดลบนชุดข้อมูล Validation

ถึงตาของคุณแล้ว ลองติดตามความแม่นยำของโมเดลด้วยชุดข้อมูล validation กัน โมเดลถูกกำหนดไว้แล้วในตัวแปร model งานของคุณคือเพิ่มโค้ดสำหรับคอมไพล์และ fit โมเดล แล้วตรวจสอบ validation score ในแต่ละ epoch

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Introduction to Deep Learning in Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • คอมไพล์โมเดลโดยใช้ 'adam' เป็น optimizer และ 'categorical_crossentropy' เป็น loss หากต้องการดูว่าการทำนายถูกต้องกี่เปอร์เซ็นต์ (accuracy) ในแต่ละ epoch ให้ระบุ keyword argument เพิ่มเติม metrics=['accuracy'] ใน model.compile()
  • Fit โมเดลโดยใช้ predictors และ target กำหนด validation split ที่ 30% (หรือ 0.3) ค่านี้จะแสดงในแต่ละ epoch

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Save the number of columns in predictors: n_cols
n_cols = predictors.shape[1]
input_shape = (n_cols,)

# Specify the model
model = Sequential()
model.add(Dense(100, activation='relu', input_shape = input_shape))
model.add(Dense(100, activation='relu'))
model.add(Dense(2, activation='softmax'))

# Compile the model
____

# Fit the model
hist = ____
แก้ไขและรันโค้ด