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

การ Undersample ข้อมูลชุด Training

ถึงเวลาทำ undersample ชุดข้อมูล training ด้วยตัวเองโดยใช้โค้ดไม่กี่บรรทัดจาก Pandas เมื่อทำ undersampling เสร็จแล้ว ลองตรวจสอบจำนวนของแต่ละค่าใน loan_status เพื่อยืนยันผลลัพธ์

X_y_train, count_nondefault และ count_default ถูกโหลดไว้ใน workspace แล้ว โดยสร้างขึ้นจากโค้ดต่อไปนี้:

X_y_train = pd.concat([X_train.reset_index(drop = True),
                       y_train.reset_index(drop = True)], axis = 1)
count_nondefault, count_default = X_y_train['loan_status'].value_counts()

ผลลัพธ์ .value_counts() ของข้อมูล training ชุดเดิมจะแสดงขึ้นมาโดยอัตโนมัติ

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

การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python

ดูคอร์ส

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

  • สร้างชุดข้อมูลของ non-defaults และ defaults แล้วเก็บไว้ในตัวแปร nondefaults และ defaults
  • สุ่มตัวอย่างจาก nondefaults ให้ได้จำนวนเท่ากับ count_default แล้วเก็บไว้เป็น nondefaults_under
  • นำ nondefaults_under และ defaults มารวมกันด้วย .concat() แล้วเก็บผลลัพธ์เป็น X_y_train_under
  • แสดงผล .value_counts() ของสถานะเงินกู้สำหรับชุดข้อมูลใหม่

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

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

# Create data sets for defaults and non-defaults
____ = ____[____[____] == 0]
____ = ____[____[____] == 1]

# Undersample the non-defaults
____ = nondefaults.sample(____)

# Concatenate the undersampled nondefaults with defaults
____ = pd.____([____.reset_index(drop = True),
                             ____.reset_index(drop = True)], axis = 0)

# Print the value counts for loan status
print(____[____].____())
แก้ไขและรันโค้ด