การเขียนโค้ดเพื่อดูว่าการเปลี่ยนค่าน้ำหนักส่งผลต่อความแม่นยำอย่างไร
ได้เวลาลองเปลี่ยนค่าน้ำหนักในโครงข่ายจริงและสังเกตว่ามันส่งผลต่อความแม่นยำของโมเดลอย่างไร!
ดูโครงข่ายประสาทเทียมต่อไปนี้:

ค่าน้ำหนักถูกโหลดไว้แล้วในตัวแปร weights_0 ภารกิจในแบบฝึกหัดนี้คือการอัปเดตค่าน้ำหนัก หนึ่ง ค่าใน weights_0 เพื่อสร้าง weights_1 ซึ่งให้การพยากรณ์ที่สมบูรณ์แบบ (ค่าที่พยากรณ์ได้เท่ากับ target_actual คือ 3)
สามารถใช้กระดาษและปากกาช่วยทดลองค่าต่างๆ ได้ โดยจะใช้ฟังก์ชัน predict_with_network() ซึ่งรับอาร์เรย์ข้อมูลเป็นอาร์กิวเมนต์แรก และค่าน้ำหนักเป็นอาร์กิวเมนต์ที่สอง
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Introduction to Deep Learning in Python
คำแนะนำการฝึกหัด
- สร้าง dictionary ของค่าน้ำหนักชื่อ
weights_1โดยเปลี่ยนค่าน้ำหนัก 1 ค่าจากweights_0(แก้ไขเพียงครั้งเดียวก็เพียงพอสำหรับการพยากรณ์ที่สมบูรณ์แบบ) - คำนวณผลการพยากรณ์ด้วยค่าน้ำหนักใหม่โดยใช้ฟังก์ชัน
predict_with_network()พร้อมกับinput_dataและweights_1 - คำนวณค่าความผิดพลาดของค่าน้ำหนักใหม่โดยการลบ
target_actualออกจากmodel_output_1 - กด 'ส่งคำตอบ' เพื่อเปรียบเทียบค่าความผิดพลาดที่ได้!
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# The data point you will make a prediction for
input_data = np.array([0, 3])
# Sample weights
weights_0 = {'node_0': [2, 1],
'node_1': [1, 2],
'output': [1, 1]
}
# The actual target value, used to calculate the error
target_actual = 3
# Make prediction using original weights
model_output_0 = predict_with_network(input_data, weights_0)
# Calculate error: error_0
error_0 = model_output_0 - target_actual
# Create weights that cause the network to make perfect prediction (3): weights_1
weights_1 = {'node_0': [____, ____],
'node_1': [____, ____],
'output': [____, ____]
}
# Make prediction using new weights: model_output_1
model_output_1 = ____
# Calculate error: error_1
error_1 = ____ - ____
# Print error_0 and error_1
print(error_0)
print(error_1)