Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Standardize the data
scaler = StandardScaler()
# Fit on training set only.
scaler.fit(X_train)
# Transform both the training set and the test set.
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)
# Make an instance of the model to retain 95% of the variance within the old features.
pca = PCA(.95)
pca.fit(X_train)
print('Number of Principal Components = '+str(pca.n_components_))
# Number of Principal Components = 13
X_train = pca.transform(X_train)
X_test = pca.transform(X_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment