การประเมินความแม่นยำของโมเดลบนชุดข้อมูล 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 = ____