Skip to content
C

Problem 3: Determine Components Needed for 95% Variance

Easypython

Problem Description

Write a Python program that applies PCA without limiting the number of components, then calculates the minimum number of components needed to explain at least 95% of the total variance.

Input

A dataset with several numeric features.

Output

The minimum number of components needed, and the cumulative variance explained.

Constraints

  • At least 5 features.

Example Input

text
(A dataset with 5 numeric features)

Example Output

text
Components needed for 95% variance: 3 Cumulative variance explained: 0.96

Concepts Covered

PCA, cumulative sum, np.cumsum().

Input (stdin)

Output

Run your code to see output here...