Error Bar Chart
ML Model Performance Comparison
Machine learning classifier comparison showing accuracy, precision, and recall with cross-validation uncertainty.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
# ML model comparison
models = ['Random\nForest', 'XGBoost', 'Neural\nNetwork', 'SVM', 'Logistic\nRegression']
accuracy = np.array([0.892, 0.905, 0.918, 0.865, 0.842])
precision = np.array([0.878, 0.895, 0.912, 0.855, 0.835])
recall = np.array([0.885, 0.898, 0.908, 0.862, 0.848])
acc_std = np.array([0.015, 0.012, 0.018, 0.020, 0.014])
prec_std = np.array([0.018, 0.015, 0.020, 0.022, 0.016])
rec_std = np.array([0.016, 0.014, 0.019, 0.021, 0.015])
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
x = np.arange(len(models))
width = 0.25
ax.bar(x - width, accuracy, width, yerr=acc_std, label='Accuracy',
color='#4927F5', edgecolor='#1f2937', capsize=3, linewidth=0.8,
error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x, precision, width, yerr=prec_std, label='Precision',
color='#27D3F5', edgecolor='#1f2937', capsize=3, linewidth=0.8,
error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x + width, recall, width, yerr=rec_std, label='Recall',
color='#F5276C', edgecolor='#1f2937', capsize=3, linewidth=0.8,
error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.axhline(y=0.9, color='#22c55e', linestyle='--', linewidth=1.5,
label='90% Target', alpha=0.7)
ax.set_xlabel('Model', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Score', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Machine Learning Model Performance Comparison', fontsize=14,
color='#1f2937', fontweight='bold', pad=15)
ax.set_xticks(x)
ax.set_xticklabels(models)
ax.legend(facecolor='#f8fafc', edgecolor='#d1d5db', fontsize=9)
ax.tick_params(colors='#6b7280', labelsize=9)
ax.set_ylim(0.75, 1.0)
ax.grid(True, axis='y', alpha=0.3, color='#d1d5db')
for spine in ax.spines.values():
spine.set_color('#d1d5db')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Error Bar Chart examples
☕