Monitoring und Visualisierung

End-to-End Machine Learning

Joshua Stapleton

Machine Learning Engineer

Was kommt als Nächstes?

  • Trainiert, optimiert, deployt, vorhergesagt … was kommt jetzt?
  • Monitoring
    • Ergebnisse loggen
    • Performance visualisieren

Monitoring-Phase im ML-Lebenszyklus

End-to-End Machine Learning

Logging mit 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

Logging mit Python (Fortsetzung)

# 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.
    ...
  • Mit Python-Logging Modellleistung nachverfolgen
End-to-End Machine Learning

Visualisierung

  • Performance über die Zeit prüfen
  • Rohdaten von Inputs/Vorhersagen in Insights verwandeln
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

Beispiel: Visualisierung

Ein Liniendiagramm mit hypothetischer Modellgenauigkeit über 12 Monate

End-to-End Machine Learning

Logging

  • Aufzeichnung von Ereignissen

    • Verfolgung von Variablenwerten, Funktionsaufrufen
    • Infos für Ausführung + Performance
  • Monitoring verfolgt u. a.:

    • Nutzung, Performance, Fehler/Anomalien
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

Visualisierungsbeispiele

  • Nützliche Kennzahl: Balanced Accuracy über die Zeit
  • Trends erkennen, Leistungsabfall sehen
  • Prüfen, ob Retraining nötig ist
  • Metriken passend zum Use Case wählen

Beispiel:

  • Balanced Accuracy vs. erwarteter Realwelt-Rate
  • Möglicher Hinweis auf ein Problem
  • Auswählen und bewerten

Visualisierung der Balanced Accuracy des Modells

End-to-End Machine Learning

Lass uns üben!

End-to-End Machine Learning

Preparing Video For Download...