AI, Dimensionality Reduction, Machine Learning, Python, Data Science.
cumulative_variance_ratio = np.cumsum(pca.explained_variance_ratio_) # Determine the number of components to keep for 85% variance explained n_components = np.argmax(cumulative_variance_ratio >= 0.85) + 1 # Apply PCA with the selected number of components pca = PCA(n_components=n_components)