Added the comments to the graph code.
This commit is contained in:
parent
2dac32eab0
commit
c2e8cfa06d
2 changed files with 5 additions and 7 deletions
2
.idea/workspace.xml
generated
2
.idea/workspace.xml
generated
|
|
@ -5,10 +5,8 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="53d2c8fc-09f6-4596-950a-66eac2662d99" name="Changes" comment="">
|
<list default="true" id="53d2c8fc-09f6-4596-950a-66eac2662d99" name="Changes" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/experiment-8.py" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/multilayer-perceptron.py" beforeDir="false" afterPath="$PROJECT_DIR$/multilayer-perceptron.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/multilayer-perceptron.py" beforeDir="false" afterPath="$PROJECT_DIR$/multilayer-perceptron.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/results/MLP-output.png" beforeDir="false" afterPath="$PROJECT_DIR$/results/MLP-output.png" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
|
|
||||||
|
|
@ -119,23 +119,23 @@ class MLP:
|
||||||
|
|
||||||
def plot_graph(self, train_losses, val_accuracies):
|
def plot_graph(self, train_losses, val_accuracies):
|
||||||
if not os.path.exists('results'):
|
if not os.path.exists('results'):
|
||||||
os.makedirs('results')
|
os.makedirs('results') # creates results director
|
||||||
|
|
||||||
fig, ax1 = plt.subplots()
|
fig, ax1 = plt.subplots() # initializes the plot
|
||||||
|
|
||||||
ax1.set_xlabel('Epochs')
|
ax1.set_xlabel('Epochs')
|
||||||
ax1.set_ylabel('Training Loss', color='tab:blue')
|
ax1.set_ylabel('Training Loss', color='tab:blue')
|
||||||
ax1.plot(range(1, len(train_losses) + 1), train_losses, color='tab:blue', label='Training Loss')
|
ax1.plot(range(1, len(train_losses) + 1), train_losses, color='tab:blue', label='Training Loss')
|
||||||
ax1.tick_params(axis='y', labelcolor='tab:blue')
|
ax1.tick_params(axis='y', labelcolor='tab:blue') # defines loss subplot
|
||||||
|
|
||||||
ax2 = ax1.twinx()
|
ax2 = ax1.twinx()
|
||||||
ax2.set_ylabel('Validation Accuracy', color='tab:orange')
|
ax2.set_ylabel('Validation Accuracy', color='tab:orange')
|
||||||
ax2.plot(range(1, len(val_accuracies) + 1), val_accuracies, color='tab:orange', label='Validation Accuracy')
|
ax2.plot(range(1, len(val_accuracies) + 1), val_accuracies, color='tab:orange', label='Validation Accuracy')
|
||||||
ax2.tick_params(axis='y', labelcolor='tab:orange')
|
ax2.tick_params(axis='y', labelcolor='tab:orange') # defines accuracy subplot
|
||||||
|
|
||||||
plt.title('Training Loss and Validation Accuracy over Epochs')
|
plt.title('Training Loss and Validation Accuracy over Epochs')
|
||||||
|
|
||||||
result_path = 'results/MLP-output.png'
|
result_path = 'results/MLP-output.png' # defines the file name
|
||||||
fig.savefig(result_path)
|
fig.savefig(result_path)
|
||||||
print(f"Graph saved to: {result_path}")
|
print(f"Graph saved to: {result_path}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue