Monday, 4 March 2024

Show graph in Python for Test accuracy and Train accuracy o various ML algorithms

 Hi all,

Please see the code.


import matplotlib.pyplot as plt

import numpy as np


# Example data (replace this with your actual data)

algorithms = ['KNN', 'ANN', 'Decision Tree', 'Ada Boost', 'Random forest', 'Naive Bayes', 'Log Regression']

test_accuracies = [0.85, 0.92, 0.78, 0.88, 0.95, 0.89, 0.91]

train_accuracies = [0.95, 0.97, 0.88, 0.93, 0.98, 0.92, 0.96]


# Set up bar positions

bar_width = 0.35

index = np.arange(len(algorithms))


# Create bar chart

fig, ax = plt.subplots()

bar1 = ax.bar(index, test_accuracies, bar_width, label='Test Accuracy')

bar2 = ax.bar(index + bar_width, train_accuracies, bar_width, label='Train Accuracy')


# Add labels, title, and legend

ax.set_xlabel('Machine Learning Algorithms')

ax.set_ylabel('Accuracy')

ax.set_title('Test and Train Accuracies of Machine Learning Algorithms')

ax.set_xticks(index + bar_width / 2)

ax.set_xticklabels(algorithms)

ax.legend()


# Show the plot

plt.show()


No comments:

Post a Comment