모니터링과 시각화

엔드 투 엔드 Machine Learning

Joshua Stapleton

Machine Learning Engineer

다음 단계는?

  • 학습, 최적화, 배포, 예측… 그다음은?
  • 모니터링
    • 결과 로깅
    • 성능 시각화

머신러닝 수명 주기의 모니터링 단계

엔드 투 엔드 Machine Learning

파이썬으로 로깅

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

파이썬으로 로깅 (계속)

# 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 로깅으로 모델 성능 추적
엔드 투 엔드 Machine Learning

시각화

  • 시간에 따른 성능 점검
  • 입력/예측의 원시 데이터를 통찰로 전환
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

시각화 예시

12개월 동안의 가상의 모델 정확도 추이를 보여주는 선 그래프

엔드 투 엔드 Machine Learning

로깅

  • 이벤트 기록

    • 변수 값, 함수 호출 추적
    • 실행·성능에 유용한 정보
  • 모니터링으로 확인:

    • 사용량, 성능, 오류/이상
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

시각화 예시

  • 유용한 지표: 시간에 따른 균형 정확도
  • 추세 파악, 성능 저하 여부 확인
  • 재학습 필요성 판단
  • 사례에 맞는 지표 선택

예시:

  • 균형 정확도가 기대치·현실 비율 대비 변동
  • 문제 징후일 수 있음
  • 지표 선택 및 평가

모델의 균형 정확도 시각화

엔드 투 엔드 Machine Learning

연습해 봅시다!

엔드 투 엔드 Machine Learning

Preparing Video For Download...