A paired histogram overlays two histograms on shared axes, splitting one numeric variable by class so distribution shape, center, spread, overlap, and separation can be compared directly. section 5.2.1
Use paired histograms to:
- Inspect whether predictor distributions resemble or differ across two classes. section 5.2.1
- Identify overlap or separation that may indicate discriminatory power for binary classification. section 5.2.1
- Guide variable selection before fitting logistic regression, without replacing formal statistical evaluation. section 5.2.1
Raisin feature comparison
Plot Area, MajorAxisLength, MinorAxisLength, Eccentricity, ConvexArea, Extent, and Perimeter for Kecimen and Besni raisins in a 3×3 Matplotlib grid. Use transparency, class labels, titles, axis labels, and legends so overlapping distributions remain interpretable. section 5.2.1
>>> import matplotlib.pyplot as plt #1
>>> fig, ((ax1, ax2, ax3), (ax4, ax5, ax6),
>>> (ax7, ax8, ax9)) = plt.subplots(nrows = 3,
>>> ncols = 3,
>>> figsize = (8, 10)) #2
>>> axes = [ax1, ax2, ax3, ax4, ax5,
>>> ax6, ax7, ax8, ax9] #3
>>> columns = ['Area', 'MajorAxisLength', 'MinorAxisLength',
>>> 'Eccentricity', 'ConvexArea',
>>> 'Extent', 'Perimeter'] #4
>>> for i, column in enumerate(columns): #5
>>> for class_label,
>>> data in raisins.groupby('Class'): \ #6
>>> data[column] \
>>> .hist(alpha = 0.5,
>>> label = class_label,
>>> ax = axes[i]) #7
>>> axes[i].set_title(f'{column}') #8
>>> axes[i].set_xlabel(column) #9
>>> axes[i].set_ylabel('Frequency') #10
>>> axes[i].legend(labels = ['Kecimen',
>>> 'Besni']) #11
>>> for ax in [ax8, ax9]: #12
>>> ax.axis('off') #13
>>> plt.tight_layout() #14
>>> plt.show() #15
Browse the Python implementation that iterates through numeric columns and grouped classes to render the paired-histogram grid. section 5.2.1

