AI, Dimensionality Reduction, Machine Learning, Python, Data Science.
random_state=42) # Standardize the data (important for PCA) scaler = StandardScaler() X_train_std = scaler.fit_transform(X_train) X_test_std = scaler.transform(X_test) # Apply PCA pca = PCA() X_train_pca = pca.fit_transform(X_train_std) # Calculate the cumulative explained variance