What is explained variance in PCA?
Updated May 16, 2026
Short answer
Explained variance in PCA measures how much of the total variation in the original data is captured by each principal component. It is represented by the eigenvalues of the covariance matrix, with larger eigenvalues indicating principal components that contain more information. The explained variance ratio helps decide how many principal components to keep while reducing dimensionality.
Deep explanation
PCA transforms the original features into a new set of features called principal components. These components are ordered so that the first component captures the maximum possible variance in the data, the second captures the next highest amount of variance, and so on.
Explained variance tells us how much of the original dataset's information is preserved by each principal component.
Understanding variance in PCA
Variance measures how spread out the data is. In PCA:
- A principal component with high variance captures a large amount of the data's structure.
- A principal component with low variance captures less important patterns, often including noise.
When PCA calculates the covariance matrix, it finds eigenvalues and eigenvectors:
- Eigenvectors represent the directions of the principal components.
- Eigenvalues represent the amount of variance explained by each principal component.
For example:
Principal Component Eigenvalue Explained Variance---------------------------------------------------------PC1 50 HighPC2 30 MediumPC3 10 LowPC4 5 Very LowPC1 explains more variation in the data than PC4, so PC1 contains more useful information.
Explained variance ratio
The explained variance ratio converts each component's variance into a percentage of the total variance.
The formula is:
Explained Variance Ratio = Variance explained by component -------------------------------- Total variance in all componentsUsing eigenvalues:
EVR(i) = λ(i) / Σλwhere:
λ(i)is the eigenvalue of the ith principal component.Σλis the sum of all eigenvalues.
Example:
Eigenvalues:PC1 = 60PC2 = 25PC3 = 10PC4 = 5
Total variance = 100The explained variance ratios are:
PC1 = 60 / 100 = 60%PC2 = 25 / 100 = 25%PC3 = 10 / 100 = 10%PC4 = 5 / 100 = 5%Together, the first two components explain:
60% + 25% = 85%This means reducing the dataset from four dimensions to two preserves 85% of the original variance.
Choosing the number of components
A common use of explained variance is selecting how many components to retain.
Typical approaches include:
- Keep components that explain a target percentage of variance, such as 90% or 95%.
- Use a scree plot to find where additional components provide diminishing returns.
- Consider the requirements of the downstream task.
Example:
Components kept: Explained variance---------------------------------------1 65%2 85%3 92%4 96%5 98%If the goal is visualization, two or three components may be enough. For a machine learning model where information loss matters, keeping components that explain 95% or more may be preferred.
Cumulative explained variance
Instead of looking at individual components, we often examine cumulative explained variance.
It answers:
"How much total information is preserved if I keep the first k components?"
Example:
PC1: 50% Cumulative: 50%PC2: 30% Cumulative: 80%PC3: 10% Cumulative: 90%PC4: 5% Cumulative: 95%PC5: 5% Cumulative: 100%If we want to preserve 90% of the variance, we only need the first three components.
Trade-offs of explained variance
Using fewer components provides benefits:
- Lower computational cost.
- Less storage required.
- Reduced noise in some cases.
- Easier visualization.
However, reducing too aggressively can:
- Remove important information.
- Reduce model performance.
- Make some patterns harder to detect.
The goal is not always to maximize explained variance. The right number of components depends on the specific application.
Example with scikit-learn
from sklearn.decomposition import PCAfrom sklearn.preprocessing import StandardScaler
# X contains the original featuresX_scaled = StandardScaler().fit_transform(X)
pca = PCA(n_components=2)X_reduced = pca.fit_transform(X_scaled)
print(pca.explained_variance_ratio_)Example output:
[0.72 0.18]Interpretation:
- The first principal component explains 72% of the variance.
- The second explains 18%.
- Together, the two components preserve 90% of the dataset's variance.
Real-world example
A company collects customer data with 100 features:
- Purchase history
- Website activity
- Demographic information
- Product preferences
- Interaction patterns
Training a machine learning model directly on all 100 features may be expensive and may include redundant information.
The company applies PCA and finds:
Number of components Cumulative explained variance----------------------------------------------------10 70%25 90%40 97%100 100%They choose 25 components because they retain 90% of the original variance while reducing the feature space by 75%.
Example:
from sklearn.decomposition import PCA
pca = PCA(n_components=0.90)
customer_features_reduced = pca.fit_transform(customer_features)
print(pca.n_components_)Using n_components=0.90 automatically keeps enough components to explain 90% of the variance.
Common mistakes
- * Assuming explained variance means the percentage of features retained rather than the percentage of data variation preserved.
- * Thinking the first principal component always represents the most important original feature
- it is actually a combination of multiple features.
- * Choosing the number of components only based on a fixed rule without considering the downstream task.
- * Forgetting that explained variance depends on feature scaling and preprocessing choices.
- * Assuming 95% explained variance guarantees that a machine learning model will retain 95% of its predictive performance.
- * Confusing explained variance with accuracy or model performance metrics.
- * Keeping all components after PCA and expecting dimensionality reduction benefits.
Follow-up questions
- How is explained variance calculated in PCA?
- Why does the first principal component have the highest explained variance?
- What is the difference between explained variance and explained variance ratio?
- How do you decide how many PCA components to keep?
- Can PCA components with low explained variance still be useful?