Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include explained variance in PCA component plot #1239

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions yellowbrick/features/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,14 @@ def finalize(self, **kwargs):
keyword arguments.
"""
super(PCA, self).finalize()

# get explained variance percentage
explained_var_perc = self.pca_transformer.named_steps['pca'].explained_variance_ratio_
# plot labels.
self.ax.set_title("Principal Component Plot")
self.ax.set_xlabel("$PC_1$")
self.ax.set_ylabel("$PC_2$")
self.ax.set_xlabel("$PC_1$ ({:0.2f}%)".format(explained_var_perc[0] * 100.))
self.ax.set_ylabel("$PC_2$ ({:0.2f}%)".format(explained_var_perc[1] * 100.))
if self.projection == 3:
self.ax.set_zlabel("$PC_3$")
self.ax.set_zlabel("$PC_3$ ({:0.2f}%)".format(explained_var_perc[2] * 100.))
if self.heatmap == True:
self.lax.set_xticks(np.arange(-0.5, len(self.features_)))
self.lax.set_xticklabels([])
Expand Down