Extend PCA Visualizer with Component-Feature Strength
See original GitHub issueDescribe the solution you’d like
Provide an optional heatmap and color bar underneath the PCA visualizer (by shifting the lower axes) that shows the magnitude of each feature value to the component. This provides an explanation of which features are contributing the most to which component.
Is your feature request related to a problem? Please describe.
Although we have the biplot mode to plot feature strengths, they can sometimes be visually overlapping or unintelligible, particularly if there is a large number of features.
Examples
Code to generate this:
fig, ax = plt.subplots(figsize=(8, 4))
plt.imshow(pca.components_, interpolation = 'none', cmap = 'plasma')
feature_names = list(cancer.feature_names)
ax.set_xticks(np.arange(-.5, len(feature_names)));
ax.set_yticks(np.arange(0.5, 2));
ax.set_xticklabels(feature_names, rotation=90, ha='left', fontsize=12);
ax.set_yticklabels(['First PC', 'Second PC'], va='bottom', fontsize=12);
plt.colorbar(orientation='horizontal', ticks=[pca.components_.min(), 0,
pca.components_.max()], pad=0.65);
Though we will probably want to use the pcolormesh
rather than imshow
as in Rank2D
, ClassificationReport
and ConfusionMatrix
. Additionally it might be a tad nicer if the color bar was above the feature plot so that the axes names were the last thing in the chart.
Notes
This idea comes from page 55-56 of Data Science Documentation. I would be happy to include a citation to this in our documentation. (HTML version is here). @mapattacker any thoughts?
See also #476 for other updates to the PCA visualizer.
Issue Analytics
- State:
- Created 5 years ago
- Comments:19 (16 by maintainers)
Top GitHub Comments
nice library! The existing biplot in this package already gives feature strengths but might not be suitable for everyone, and can be difficult to visualise when there are too many features overlapping each other. this is indeed a good additional feature to add in for PCA @bbengfort .
I don’t think so - let’s close this as fixed in #884 and #937