การติดตามและการแสดงผล

Machine Learning แบบ End-to-End

Joshua Stapleton

Machine Learning Engineer

ต่อไปคืออะไร?

  • เทรน ปรับแต่ง ดีพลอย พยากรณ์... แล้วอะไรต่อ?
  • การติดตาม (Monitoring)
    • บันทึก Log ผลลัพธ์
    • แสดงผลประสิทธิภาพ

ขั้นตอนการติดตามในวงจรชีวิต machine learning

Machine Learning แบบ End-to-End

การบันทึก Log ด้วย Python

import logging
import matplotlib.pyplot as plt

# Setting up basic logging configuration
logging.basicConfig(filename='predictions.log', level=logging.INFO)

# Make predictions on the test set and log the results
for i in range(X_test.shape[0]):
    instance = X_test[i,:].reshape(1, -1)
    prediction = model.predict(instance)
    logging.info(f'Inst. {i} - PredClass: {prediction[0]}, RealClass: {y_test[i]}')
Machine Learning แบบ End-to-End

การบันทึก Log ด้วย Python (ต่อ)

# Function to visualize the predictions from log
with open(logfile, 'r') as f:
    lines = f.readlines()
    predicted_classes = [int(line.split("Predicted Class: ")[1].split(",")[0]) \
        for line in lines]

    # Perform data analysis, visualization, etc.
    ...
  • ใช้ Python logging เพื่อติดตามประสิทธิภาพของโมเดล
Machine Learning แบบ End-to-End

การแสดงผล (Visualization)

  • ตรวจสอบประสิทธิภาพตามช่วงเวลา
  • แปลงข้อมูลดิบของ input / การพยากรณ์ให้เป็น insight
import matplotlib.pyplot as plt

# Sample data: Random accuracy values for 12 months months = ["Jan", "Feb", "Mar", ...] accuracies = [0.86, 0.91, 0.74, ...]
plt.plot(months, accuracies, '-o') plt.title("Model Accuracy Over Months") plt.xlabel("Months") plt.ylabel("Accuracy") plt.show()
Machine Learning แบบ End-to-End

ตัวอย่างการแสดงผล

กราฟเส้นแสดงความแม่นยำของโมเดลในช่วง 12 เดือน

Machine Learning แบบ End-to-End

การบันทึก Log

  • การบันทึกเหตุการณ์

    • ติดตามค่าตัวแปร การเรียกใช้ฟังก์ชัน
    • ข้อมูลที่สะท้อนการทำงานและประสิทธิภาพ
  • การติดตาม (Monitoring) ช่วยวัด:

    • การใช้งาน, ประสิทธิภาพ, ข้อผิดพลาด/ความผิดปกติ
2023-08-04 09:15:20 [INFO] Model version 1.2.7 started

2023-08-04 09:15:45 [INFO] Preprocessing input data for prediction
2023-08-04 09:15:47 [DEBUG] Input data shape: (1, 12)
2023-08-04 09:15:48 [INFO] Making prediction
2023-08-04 09:15:50 [DEBUG] Output prediction: [0.78]
...
Machine Learning แบบ End-to-End

ตัวอย่างการแสดงผล

  • เมตริกที่มีประโยชน์: balanced accuracy ตามช่วงเวลา
  • สังเกตแนวโน้ม และตรวจสอบว่าประสิทธิภาพลดลงหรือไม่
  • พิจารณาว่าถึงเวลาเทรนโมเดลใหม่หรือยัง
  • เลือกเมตริกที่เหมาะกับกรณีใช้งาน

ตัวอย่าง:

  • Balanced accuracy เปลี่ยนแปลงเทียบกับอัตราที่คาดไว้ในโลกจริง
  • อาจบ่งชี้ถึงปัญหาที่เกิดขึ้น
  • เลือกและประเมินผล

การแสดงผล balanced accuracy ของโมเดล

Machine Learning แบบ End-to-End

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

Machine Learning แบบ End-to-End

Preparing Video For Download...