What is explained variance ratio in PCA?
Updated May 17, 2026
Short answer
The explained variance ratio in PCA measures the proportion of the dataset's total variance that is captured by each principal component. It is calculated by dividing the variance explained by a component (its eigenvalue) by the sum of variances explained by all components. It helps determine how many principal components should be retained while preserving as much information from the original data as possible.
Deep explanation
In Principal Component Analysis (PCA), the goal is to transform a dataset with potentially correlated features into a new set of uncorrelated features called principal components. Each principal component represents a direction in the feature space along which the data has the most variance.
The explained variance ratio tells us how much of the total variation in the original dataset is captured by each principal component.
For a dataset with n features, PCA produces n principal components. Each component has an associated eigenvalue, which represents the amount of variance captured by that component.
The explained variance ratio for principal component (i) is:
[ \text{Explained Variance Ratio}i = \frac{\lambda_i}{\sum{j=1}^{n}\lambda_j} ]
where:
- (\lambda_i) is the eigenvalue of the (i)-th principal component.
- The denominator is the sum of all eigenvalues, representing the total variance in the dataset.
The ratios for all components add up to 1:
[ \sum_{i=1}^{n} \text{Explained Variance Ratio}_i = 1 ]
For example, if PCA produces these explained variance ratios:
PC1: 0.60PC2: 0.25PC3: 0.10PC4: 0.05it means:
- The first principal component captures 60% of the dataset's variance.
- The first two components together capture 85% of the variance.
- Keeping only the first two components reduces dimensionality while retaining most of the information.
Cumulative Explained Variance
A common use of explained variance ratio is calculating cumulative explained variance:
[ \text{Cumulative Variance}k = \sum{i=1}^{k}\text{Explained Variance Ratio}_i ]
This helps choose the number of components to keep.
For example:
Components kept Cumulative explained variance1 60%2 85%3 95%4 100%A machine learning workflow might choose three components if 95% variance retention is considered sufficient.
Why Explained Variance Matters
PCA reduces dimensionality by discarding components with small explained variance. Components with low variance often contain less information, noise, or redundant patterns.
However, explained variance is not the same as predictive importance:
- A component explaining little variance may still contain information useful for a specific prediction task.
- A component explaining large variance may capture irrelevant variation, such as measurement scale or background noise.
Therefore, explained variance is mainly a measure of information preservation, not necessarily model performance.
Relationship With Eigenvalues
PCA works by decomposing the covariance matrix of standardized features:
[ C = Q \Lambda Q^T ]
where:
- (Q) contains eigenvectors, which define the principal component directions.
- (\Lambda) contains eigenvalues, which represent variance along those directions.
The eigenvalues are used directly to calculate explained variance ratios.
Practical PCA Workflow
A typical PCA workflow is:
- Standardize features so variables with larger scales do not dominate.
- Compute principal components.
- Examine explained variance ratios.
- Select a suitable number of components.
- Transform the data into the reduced feature space.
Example:
from sklearn.preprocessing import StandardScalerfrom sklearn.decomposition import PCA
X_scaled = StandardScaler().fit_transform(X)
pca = PCA()pca.fit(X_scaled)
print(pca.explained_variance_ratio_)The output might be:
[0.52, 0.28, 0.12, 0.05, 0.03]This indicates that the first two components capture:
[ 0.52 + 0.28 = 0.80 ]
or 80% of the total variance.
Trade-offs When Selecting Components
Keeping more components:
- Preserves more information.
- Reduces less dimensionality.
- Requires more memory and computation.
Keeping fewer components:
- Provides stronger compression.
- Can reduce noise.
- May remove useful information.
The correct threshold depends on the application. Common choices are 90%, 95%, or 99% cumulative explained variance, but these are heuristics rather than strict rules.
Real-world example
Suppose a company collects customer behavior data with 100 features:
- Number of purchases
- Average order value
- Website activity
- Product category preferences
- Support interactions
- Marketing engagement metrics
Many of these features are correlated. For example, customers who visit frequently may also purchase frequently and interact more with marketing campaigns.
Applying PCA may produce:
PC1: 45% variancePC2: 25% variancePC3: 15% variancePC4-PC100: 15% varianceThe company can keep the first three components and represent each customer using only three new features while preserving 85% of the original variance.
A simplified implementation:
from sklearn.preprocessing import StandardScalerfrom sklearn.decomposition import PCA
# X contains 100 customer behavior featuresX_scaled = StandardScaler().fit_transform(X)
pca = PCA(n_components=0.85)X_reduced = pca.fit_transform(X_scaled)
print(X_reduced.shape)print(pca.explained_variance_ratio_)Using n_components=0.85 tells scikit-learn to automatically keep enough components to explain at least 85% of the variance.
This reduced representation can then be used for clustering, visualization, anomaly detection, or as input features for another machine learning model.
Common mistakes
- * Assuming explained variance ratio measures predictive power rather than variance preservation.
- * Applying PCA before standardizing features when variables have significantly different scales.
- * Keeping only the first principal component because it explains the most variance without checking cumulative explained variance.
- * Assuming components with low explained variance are always useless for downstream tasks.
- * Using PCA without considering interpretability requirements, since principal components are combinations of original features.
- * Choosing a fixed variance threshold like 95% without validating whether it improves the actual business or modeling objective.
Follow-up questions
- Why is feature scaling important before applying PCA?
- How do you decide how many principal components to keep?
- What is the difference between explained variance and explained variance ratio?
- Can PCA improve machine learning model performance?
- Why do PCA components become uncorrelated?