監視と可視化

End-to-End Machine Learning

Joshua Stapleton

Machine Learning Engineer

次は何をするか

  • 学習・最適化・デプロイ・予測…その次は?
  • 監視
    • 結果のログ記録
    • 性能の可視化

機械学習ライフサイクルの監視フェーズ

End-to-End Machine Learning

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]}')
End-to-End Machine Learning

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でモデル性能を追跡
End-to-End 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()
End-to-End Machine Learning

可視化例

12か月間の仮想的なモデル精度の折れ線グラフ

End-to-End 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]
...
End-to-End Machine Learning

可視化の例

  • 有用な指標: 時系列のバランス精度
  • 傾向や劣化を把握
  • 再学習の要否を判断
  • 目的に合う指標を選定

例:

  • 期待される実環境の比率に対するバランス精度の変化
  • 問題の兆候の可能性
  • 指標を選び評価

モデルのバランス精度の可視化

End-to-End Machine Learning

¡Vamos a practicar!

End-to-End Machine Learning

Preparing Video For Download...