Created
August 3, 2018 20:31
-
-
Save ImadDabbura/072be81d733ed0c59e4fe334b40dcaee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Build PCA using standarized trained data | |
| pca = PCA(n_components=None, svd_solver="full") | |
| pca.fit(StandardScaler().fit_transform(X_train)) | |
| cum_var_exp = np.cumsum(pca.explained_variance_ratio_) | |
| plt.figure(figsize=(12, 6)) | |
| plt.bar(range(1, 18), pca.explained_variance_ratio_, align="center", | |
| color='red', label="Individual explained variance") | |
| plt.step(range(1, 18), cum_var_exp, where="mid", label="Cumulative explained variance") | |
| plt.xticks(range(1, 18)) | |
| plt.legend(loc="best") | |
| plt.xlabel("Principal component index", {"fontsize": 14}) | |
| plt.ylabel("Explained variance ratio", {"fontsize": 14}) | |
| plt.title("PCA on training data", {"fontsize": 16}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment