Last active
November 14, 2018 23:48
-
-
Save GeorgeSeif/48e7d74fb5fd57b96c068fbfffdd616a 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
| # Only keep a certain number of eigen vectors based on | |
| # the "explained variance percentage" which tells us how | |
| # much information (variance) can be attributed to each | |
| # of the principal components | |
| exp_var_percentage = 0.97 # Threshold of 97% explained variance | |
| tot = sum(eig_vals) | |
| var_exp = [(i / tot)*100 for i in sorted(eig_vals, reverse=True)] | |
| cum_var_exp = np.cumsum(var_exp) | |
| num_vec_to_keep = 0 | |
| for index, percentage in enumerate(cum_var_exp): | |
| if percentage > exp_var_percentage: | |
| num_vec_to_keep = index + 1 | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment