-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualization.py
39 lines (32 loc) · 1.19 KB
/
visualization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import matplotlib.pyplot as plt
def plot_training_history(history):
"""
Plots the training and validation loss and accuracy curves.
Args:
- history: History object returned by the model.fit() method.
"""
# Plot training and validation loss
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.plot(history.history['loss'], label='Training Loss')
plt.plot(history.history['val_loss'], label='Validation Loss')
plt.title('Training and Validation Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.legend()
# Plot training and validation accuracy
plt.subplot(1, 2, 2)
plt.plot(history.history['accuracy'], label='Training Accuracy')
plt.plot(history.history['val_accuracy'], label='Validation Accuracy')
plt.title('Training and Validation Accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.legend()
plt.show()
# Add more visualization functions as needed (e.g., confusion matrix, sample predictions)
# Example usage
if __name__ == "__main__":
# Load the training history from a file or variable
history = # Load your training history here
# Plot training history
plot_training_history(history)