การทดสอบโมเดล

Machine Learning แบบ End-to-End

Joshua Stapleton

Machine Learning Engineer

Deployment

  • ขั้นตอนต่อไปใน ML lifecycle
  • หลังการฝึกและประเมินผล
  • นำโมเดลไปใช้งานจริง

ขั้นตอน Deployment ใน machine learning lifecycle

Machine Learning แบบ End-to-End

การทดสอบ

  • การทดสอบ:
    • โมเดลไม่ crash
    • ส่งออกผลลัพธ์ที่สมเหตุสมผลในขั้นตอน inference
    • ส่งออกผลลัพธ์ภายในเวลาที่เหมาะสม

ขั้นตอน Deployment ใน machine learning lifecycle

Machine Learning แบบ End-to-End

Unittest

  • การทดสอบ
    • ตรวจจับเหตุการณ์ผิดปกติหรือไม่คาดคิด
    • ตรวจสอบว่าโมเดลทำงานได้ตามที่คาดไว้

 

  • unittest
    • ไลบรารีในตัวของ Python สำหรับเขียนเทสต์
    • Test case: ครอบคลุมประเภทของการทดสอบ
    • Test case method: การทดสอบเดี่ยวสำหรับแต่ละแง่มุมของ test case
Machine Learning แบบ End-to-End

การใช้งาน Unittest

import unittest


class TestModelInference(unittest.TestCase):
def setUp(self): self.model = fitted_model self.X_test = X_test
def test_prediction_output_shape(self): y_pred = self.model.predict(self.X_test) self.assertEqual(y_pred.shape[0], self.X_test.shape[0])
if __name__ == '__main__': unittest.main()
Machine Learning แบบ End-to-End

การใช้งาน Unittest (ต่อ)

 

    def test_input_values(self):
        print("Running test_input_values test case")

        # Get inputs (each row in testing set)
        for input in X_test: 
            for value in input:
                # if value is cholestrol, for example:
                self.assertIn(value, [0, 500])
Machine Learning แบบ End-to-End

Testing in Python

Machine Learning แบบ End-to-End

ควรและไม่ควรทำในการทดสอบ

แนวทางปฏิบัติที่ดี

  • ไม่ควร...
    • เขียนเทสต์มากเกินไป
    • เขียนเทสต์ที่ซ้ำซ้อน
    • เขียนเทสต์สำหรับส่วนประกอบที่เชื่อถือได้อยู่แล้ว

 

  • ควร...
    • เขียนเทสต์เพื่อเพิ่มความน่าเชื่อถือ
    • เขียนเทสต์เพื่อตรวจสอบและจัดการความคาดหวัง
    • เขียนเทสต์สำหรับฟังก์ชันใหม่
Machine Learning แบบ End-to-End

ประโยชน์ของการทดสอบ

ประโยชน์ของ TDD

  • ความมั่นใจในการพัฒนา
    • การทำซ้ำที่เสถียร
    • กังวลเรื่อง bug น้อยลง
  • ประสิทธิภาพ
    • ความน่าเชื่อถือ
    • พร้อมใช้งานระดับ production
Machine Learning แบบ End-to-End

มาฝึกกันเถอะ!

Machine Learning แบบ End-to-End

Preparing Video For Download...