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

กลับมาทบทวนเรื่อง Contamination

คุณสังเกตว่า one-class SVM ไม่มีพารามิเตอร์ contamination แต่ถึงตอนนี้คุณรู้ดีแล้วว่าจำเป็นต้องมีวิธีควบคุมสัดส่วนของตัวอย่างที่ถูกระบุว่าเป็น novelty เพื่อควบคุม false positive rate จึงตัดสินใจทดลองใช้การกำหนด threshold กับ scores โดย detector ถูก import มาในชื่อ onesvm และมีข้อมูล X_train, X_test, y_train, y_test, numpy ในชื่อ np และฟังก์ชัน confusion_matrix() พร้อมใช้งาน

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

การออกแบบ Machine Learning Workflows ด้วย Python

ดูคอร์ส

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

  • Fit โมเดล 1-class SVM และให้คะแนนข้อมูลชุดทดสอบ
  • คำนวณสัดส่วนที่สังเกตได้ของ outlier ในข้อมูลชุดทดสอบ
  • ใช้ np.quantile() เพื่อหาจุด threshold ของ scores ที่ทำให้ได้สัดส่วนดังกล่าว
  • นำ threshold นั้นไปกำหนดป้ายกำกับข้อมูลชุดทดสอบ แล้วแสดง confusion matrix

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

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

# Fit a one-class SVM detector and score the test data
nov_det = ____(X_train)
scores = ____(X_test)

# Find the observed proportion of outliers in the test data
prop = np.____(y_test==____)

# Compute the appropriate threshold
threshold = np.____(____, ____)

# Print the confusion matrix for the thresholded scores
print(confusion_matrix(y_test, ____ > ____))
แก้ไขและรันโค้ด