Monitoring en visualisatie

End-to-End Machine Learning

Joshua Stapleton

Machine Learning Engineer

Wat is de volgende stap?

  • Getraind, geoptimaliseerd, gedeployed, voorspeld... en dan?
  • Monitoring
    • Resultaten loggen
    • Performance visualiseren

Monitoringsfase in de machine-learning-levenscyclus

End-to-End Machine Learning

Logging met 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 met Python (vervolg)

# 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.
    ...
  • Gebruik Python logging om modelperformance te traceren
End-to-End Machine Learning

Visualisatie

  • Inspecteer performance in de tijd
  • Zet ruwe input-/voorspelddata om in inzichten
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

Voorbeeld visualisatie

Een lijngrafiek met hypothetische modelaccuratesse over 12 maanden

End-to-End Machine Learning

Logging

  • Vastleggen van events

    • Bijhouden van variabelewaarden, functieaanroepen
    • Info die uitvoering + performance inzichtelijk maakt
  • Monitoring helpt bij:

    • Gebruik, performance, fouten/afwijkingen
2023-08-04 09:15:20 [INFO] Modelversie 1.2.7 gestart

2023-08-04 09:15:45 [INFO] Preprocessing inputdata voor voorspelling
2023-08-04 09:15:47 [DEBUG] Vorm inputdata: (1, 12)
2023-08-04 09:15:48 [INFO] Voorspelling maken
2023-08-04 09:15:50 [DEBUG] Outputvoorspelling: [0.78]
...
End-to-End Machine Learning

Voorbeelden visualisatie

  • Nuttige metric: balanced accuracy over tijd
  • Trends spotten, zien of performance afneemt
  • Bepalen of retraining nodig is
  • Kies metrics passend bij je use-case

Voorbeeld:

  • Balanced accuracy vs. verwachte, real-world rate
  • Mogelijk teken van een probleem
  • Kies en evalueer

Visualisatie van de balanced accuracy van het model

End-to-End Machine Learning

Laten we oefenen!

End-to-End Machine Learning

Preparing Video For Download...