AI, Dimensionality Reduction, Machine Learning, Python, Data Science.
PCA() is initially applied without specifying the number of components, which means it will keep all components. Then, the cumulative explained variance is calculated using np.cumsum(pca.explained_variance_ratio_). Finally, the number of components required to explain at least 85% of the variance