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

การกำหนดโมเดลและฟังก์ชันความสูญเสีย

ในแบบฝึกหัดนี้ จะได้ฝึกโครงข่ายประสาทเทียมเพื่อทำนายว่าผู้ถือบัตรเครดิตจะผิดนัดชำระหนี้หรือไม่ ฟีเจอร์และเป้าหมายที่ใช้ในการฝึกโมเดลพร้อมใช้งานใน Python shell ในชื่อ borrower_features และ default โดยที่ weights และ biases ถูกกำหนดไว้แล้วในแบบฝึกหัดก่อนหน้า

เลเยอร์ predictions ถูกนิยามเป็น \(\sigma(layer1*w2+b2)\) โดยที่ \(\sigma\) คือ sigmoid activation, layer1 คือเทนเซอร์ของโหนดในเลเยอร์ hidden dense แรก, w2 คือเทนเซอร์ของ weights และ b2 คือเทนเซอร์ของ bias

ตัวแปรที่ฝึกได้ ได้แก่ w1, b1, w2 และ b2 นอกจากนี้ ยังมีการนำเข้าฟังก์ชันต่อไปนี้ไว้ให้แล้ว: keras.activations.relu() และ keras.layers.Dropout()

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

TensorFlow เบื้องต้นใน Python

ดูคอร์ส

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

  • ใช้ฟังก์ชัน activation แบบ rectified linear unit กับเลเยอร์แรก
  • ใช้ dropout 25% กับ layer1
  • ส่งค่าเป้าหมาย targets และค่าที่ทำนายได้ predictions ไปยังฟังก์ชัน cross entropy loss

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

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

# Define the model
def model(w1, b1, w2, b2, features = borrower_features):
	# Apply relu activation functions to layer 1
	layer1 = keras.activations.____(matmul(features, w1) + b1)
    # Apply dropout rate of 0.25
	dropout = keras.layers.Dropout(____)(____)
	return keras.activations.sigmoid(matmul(dropout, w2) + b2)

# Define the loss function
def loss_function(w1, b1, w2, b2, features = borrower_features, targets = default):
	predictions = model(w1, b1, w2, b2)
	# Pass targets and predictions to the cross entropy loss
	return keras.losses.binary_crossentropy(____, ____)
แก้ไขและรันโค้ด