Created
May 21, 2019 22:28
-
-
Save AVJdataminer/7696453c2e9b635c857b392f792bf36f to your computer and use it in GitHub Desktop.
This file contains 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
import sklearn.decomposition | |
pca = sklearn.decomposition.PCA() | |
pca.fit(X) | |
variances = pca.explained_variance_ratio_ | |
def select_n_components(var_ratio, goal_var: float) -> int: | |
total_variance = 0.0 | |
n_components = 0 | |
# For the explained variance of each feature: | |
for explained_variance in var_ratio: | |
# Add the explained variance to the total | |
total_variance += explained_variance | |
# Add one to the number of components | |
n_components += 1 | |
if total_variance >= goal_var: | |
# End the loop | |
break | |
# Return the number of components | |
return n_components | |
pca = sklearn.decomposition.PCA(n1) | |
pca.fit(X) | |
XP=pca.components_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment