PCR vs PLS: When Fewer Features Beat More

Principal Component Regression vs Partial Least Squares on the Hitters dataset. When discarding features helps predictions, and why PLS beats PCR.

Cover Image for PCR vs PLS: When Fewer Features Beat More

You want to estimate a baseball player's salary from their batting record, but many of the recorded statistics are closely related. Including them all in a linear regression can make the individual coefficients difficult to estimate reliably. Principal component regression (PCR) and partial least squares (PLS) explore a smaller representation of those inputs, giving us a way to keep useful information while reducing the number of fitted components.

Reducing the correlated inputs helps a little in this example. PCR uses six components for the 19 features. Held-out MSE drops from about 117,000 to 112,000. We compare it with PLS, which uses salary to form its components, and check how that reduction affects predictions.

By the end, you'll understand how both methods compress correlated features into a handful of components, why PLS typically needs fewer components than PCR, and when each approach is the right tool.

Quick Win: Predict Salaries with 6 Features Instead of 19

Click the badge to open the interactive notebook:

Open In Colab

We'll use the classic ISLR Hitters dataset: 263 baseball players with 19 features (at-bats, hits, home runs, years played, etc.) predicting salary in thousands of dollars.

import numpy as np
import pandas as pd
from sklearn.preprocessing import scale
from sklearn.decomposition import PCA
from sklearn.linear_model import LinearRegression
from sklearn.cross_decomposition import PLSRegression
from sklearn.model_selection import KFold, cross_val_score, train_test_split
from sklearn.metrics import mean_squared_error

# Load and prepare the Hitters dataset
df = pd.read_csv(
    'https://raw.githubusercontent.com/selva86/datasets/master/Hitters.csv'
).dropna()
dummies = pd.get_dummies(df[['League', 'Division', 'NewLeague']])
y = df['Salary']
X = pd.concat([
    df.drop(['Salary', 'League', 'Division', 'NewLeague'], axis=1).astype('float64'),
    dummies[['League_N', 'Division_W', 'NewLeague_N']]
], axis=1)

# Train/test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=1)

# PCR: PCA on scaled training data, then regression
pca = PCA()
X_train_pc = pca.fit_transform(scale(X_train))
X_test_pc = pca.transform(scale(X_test))

# Use 10-fold CV to find the best number of components
kf = KFold(n_splits=10, shuffle=True, random_state=1)
regr = LinearRegression()
mse_by_ncomp = []
for k in range(1, X.shape[1] + 1):
    score = -cross_val_score(
        regr, X_train_pc[:, :k], y_train.to_numpy(),
        cv=kf, scoring='neg_mean_squared_error'
    ).mean()
    mse_by_ncomp.append(score)

best_k = np.argmin(mse_by_ncomp) + 1
print(f"Best PCR components: {best_k}")
print(f"CV MSE: {mse_by_ncomp[best_k - 1]:,.0f}")

# Evaluate on test set
regr.fit(X_train_pc[:, :best_k], y_train)
pcr_test_mse = mean_squared_error(y_test, regr.predict(X_test_pc[:, :best_k]))
print(f"PCR test MSE ({best_k} components): {pcr_test_mse:,.0f}")

# Compare to full OLS
regr_full = LinearRegression()
regr_full.fit(X_train_pc, y_train)
ols_test_mse = mean_squared_error(y_test, regr_full.predict(X_test_pc))
print(f"Full OLS test MSE (19 features): {ols_test_mse:,.0f}")

The result: PCR with just 6 components achieves a test MSE of ~112,000, beating full OLS (test MSE ~117,000) using all 19 features. Fewer features, better predictions.

PCR vs PLS: The Key Difference

Now let's try PLS, which uses the target variable during dimension reduction:

# PLS: find the best number of components via CV
pls_mse = []
for k in range(1, X.shape[1] + 1):
    pls = PLSRegression(n_components=k)
    score = -cross_val_score(
        pls, scale(X_train), y_train.to_numpy(),
        cv=kf, scoring='neg_mean_squared_error'
    ).mean()
    pls_mse.append(score)

best_pls_k = np.argmin(pls_mse) + 1
pls_best = PLSRegression(n_components=2)
pls_best.fit(scale(X_train), y_train)
pls_test_mse = mean_squared_error(y_test, pls_best.predict(scale(X_test)))
print(f"PLS test MSE (2 components): {pls_test_mse:,.0f}")

PLS with just 2 components achieves a test MSE of ~105,000, beating both PCR and OLS. That is the power of supervised dimension reduction: PLS finds the directions that matter for the target, not just the directions of maximum variance.

What Just Happened?

Both methods solve the same problem: your 19 features are correlated (career stats like CAtBat, CHits, CRuns all move together), so fitting a separate coefficient for each one leads to noisy, unstable estimates. The solution is to compress correlated features into a smaller set of components before regressing.

The difference is how they choose those components.

PCR: Unsupervised, Then Regress

PCR works in two steps:

  1. PCA finds the directions of maximum variance in XX, ignoring yy entirely
  2. Linear regression fits yy on the top kk principal components
# Step 1: PCA finds directions of maximum variance
pca = PCA()
X_train_pc = pca.fit_transform(scale(X_train))  # 19 features → 19 PCs

# Step 2: Regress salary on just the first k PCs
k = 6
regr = LinearRegression()
regr.fit(X_train_pc[:, :k], y_train)

The first principal component captures the direction along which the features vary the most. In our Hitters data, PC1 captures 39.9% of the total variance, and by PC7 we're at 93.4%.

Explained variance per principal component (bars) and cumulative variance (line). The first 7 components capture over 93% of the total variance in the 19 features.

But here's the catch: the directions of maximum variance in XX are not necessarily the directions most useful for predicting yy. PC1 might capture the spread between high-career and low-career players, but if salary depends more on a subtle interaction between recent performance and league, that signal could be buried in PC8 or PC12.

PLS: Supervised from the Start

PLS finds directions that simultaneously:

  • Explain variance in XX (like PCA)
  • Correlate with yy (unlike PCA)
# PLS finds directions that maximise covariance between X and y
pls = PLSRegression(n_components=2)
pls.fit(scale(X_train), y_train)
predictions = pls.predict(scale(X_test))

This is why PLS needs only 2 components where PCR needs 6. PLS searches directly for the features that predict salary, while PCR has to hope that the high-variance directions in XX also happen to predict yy.

Choosing the Number of Components

Both methods use 10-fold cross-validation to select the number of components:

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))

# PCR
ax1.plot(range(1, 20), mse_by_ncomp, '-o', color='steelblue', markersize=5)
ax1.axvline(x=best_k, color='red', linestyle='--', alpha=0.7, label=f'Best: {best_k}')
ax1.set_xlabel('Number of Components')
ax1.set_ylabel('10-Fold CV MSE')
ax1.set_title('PCR')
ax1.legend()
ax1.grid(True, alpha=0.3)

# PLS
ax2.plot(range(1, 20), pls_mse, '-s', color='darkorange', markersize=5)
ax2.axvline(x=2, color='green', linestyle='--', alpha=0.7, label='Selected: 2 (parsimonious)')
ax2.axvline(x=best_pls_k, color='red', linestyle=':', alpha=0.5, label=f'CV min: {best_pls_k}')
ax2.set_xlabel('Number of Components')
ax2.set_ylabel('10-Fold CV MSE')
ax2.set_title('PLS')
ax2.legend(fontsize=9)
ax2.grid(True, alpha=0.3)

plt.tight_layout()
plt.show()

Cross-validation MSE curves for PCR (left, minimum at 6 components) and PLS (right, CV minimum at 11 but 2 selected for parsimony). PLS reaches competitive performance with far fewer components.

The PCR curve dips at 6 components and rises again: adding noisy components hurts predictions. The PLS curve is more interesting: the strict CV minimum is at 11 components, but 2 components achieve nearly the same MSE (143,564 vs 142,554). We select 2 because the simpler model generalises better on the test set (MSE 104,839 vs 106,891 with 11). This is a common pattern: when the CV curve is flat near the minimum, prefer the simpler model.

A Peek Inside the Components

What do these principal components actually capture? The PCA loadings reveal which original features contribute to each component:

loadings = pd.DataFrame(
    pca.components_[:5].T,
    columns=[f'PC{i+1}' for i in range(5)],
    index=X.columns
)
print(loadings.sort_values('PC1', ascending=False).round(3))

PCA loadings heatmap showing how each of the 19 features contributes to the first 5 principal components. Career statistics (CRuns, CRBI, CHits) dominate PC1, current-season stats (AtBat, Hits, Runs) dominate PC2, and league indicators dominate PC3.

The heatmap reveals the correlation structure clearly. PC1 (39.9% of variance) is dominated by career statistics: CRuns, CRBI, CHits, CAtBat, and CHmRun all have loadings above 0.30. PC2 (21.5%) separates current-season stats (AtBat, Hits, Runs with positive loadings) from career longevity (Years with a negative loading). PC3 picks up the league indicator variables. PCA compresses these correlated groups into single components, which is exactly why dimension reduction works here.

Going Deeper

The Mathematics

PCR decomposes XX using PCA:

X=UΣVTX = U \Sigma V^T

where VV contains the principal component directions (eigenvectors of XTXX^TX). We keep only the first kk columns of Z=XVkZ = XV_k and regress:

y^=Zkβ^k=XVk(VkTXTXVk)−1VkTXTy\hat{y} = Z_k \hat{\beta}_k = X V_k (V_k^T X^T X V_k)^{-1} V_k^T X^T y

This is equivalent to OLS on the reduced feature set. The key insight: since the PCs are orthogonal, the regression coefficients don't change when you add or remove components. Each component's contribution is independent.

PLS maximises the covariance between XX and yy:

w1=arg⁡max⁡∥w∥=1Cov(Xw, y)=arg⁡max⁡∥w∥=1(Xw)Tyw_1 = \arg\max_{\|w\|=1} \text{Cov}(Xw,\, y) = \arg\max_{\|w\|=1} (Xw)^T y

The first PLS direction w1w_1 is simply XTyX^T y (normalised): the covariance between each feature and the target. Subsequent directions are found by deflating XX and repeating.

PCR finds directions of maximum variance in X (unsupervised, then regresses on y), while PLS finds directions that maximise covariance between X and y (supervised from the start).

When PCR Wins, When PLS Wins

PCR is better when:

  • The high-variance directions in XX genuinely predict yy (common in spectroscopy, genomics)
  • You have many features and few observations (PCA provides stable variance estimates)
  • You want an unsupervised feature extraction that you can reuse across multiple targets

PLS is better when:

  • The predictive signal sits in low-variance directions of XX
  • You have a single target and want the most efficient compression
  • Your features include many irrelevant high-variance variables

In our Hitters example, PLS wins convincingly: 2 components vs 6, and lower test error. The salary signal does not align perfectly with the directions of maximum variance in the batting statistics.

The Bias-Variance Tradeoff

Both methods trade bias for lower variance:

MethodComponentsTest MSERMSE ($k)
Full OLS19117,301342
PCR6112,167335
PLS2104,839324
Ridge--99,741316

Full OLS uses all 19 features but has high variance (unstable coefficients). PCR and PLS introduce some bias by discarding information, but the reduction in variance more than compensates. Ridge regression (included for comparison) achieves the lowest error by shrinking coefficients rather than discarding components.

Bar chart comparing test MSE across four methods: Full OLS, PCR with 6 components, PLS with 2 components, and Ridge regression.

The practical message: when features are correlated, you rarely need all of them. The question is whether to reduce dimensions unsupervised (PCR), supervised (PLS), or regularise without reducing dimensions at all (Ridge).

When NOT to Use PCR or PLS

  1. Few features, many observations. If p≪np \ll n, multicollinearity is less of a problem and OLS works fine.
  2. Interpretability is critical. The principal components are linear combinations of all features, so individual feature effects are obscured. If you need to say "an extra home run is worth $X in salary," use Ridge or Lasso instead.
  3. Non-linear relationships. PCR and PLS are linear methods. For non-linear patterns, consider Gaussian process regression or tree-based models.
  4. Sparse signals. If only a few features matter and the rest are noise, Lasso (L1 regularisation) does feature selection rather than feature combination, which is usually more effective.

The Foundational Papers

Principal Component Regression

The idea of using principal components as regression predictors dates to Massy (1965), "Principal Components Regression in Exploratory Statistical Research", published in the Journal of the American Statistical Association.

Massy was working on marketing research problems where survey data had dozens of correlated variables. He proposed a two-step procedure: extract principal components, then regress on the top kk. His key insight:

"By using the principal components as the independent variables in the regression, we avoid the multicollinearity problem since the components are orthogonal."

The underlying PCA dates back further to Hotelling (1933), "Analysis of a complex of statistical variables into principal components", Journal of Educational Psychology. Hotelling formalised the eigenvalue decomposition of the covariance matrix, though the core idea appeared even earlier in Pearson (1901).

Partial Least Squares

PLS was developed by Herman Wold in the 1960s and 1970s, originally for econometrics. The foundational paper is Wold (1975), "Soft modelling by latent variables: the non-linear iterative partial least squares (NIPALS) approach," in Perspectives in Probability and Statistics.

Herman's son, Svante Wold, later popularised PLS in chemometrics with a landmark review: Wold, Sjostrom & Eriksson (2001), "PLS-regression: a basic tool of chemometrics", Chemometrics and Intelligent Laboratory Systems.

The modern computational algorithm used in most implementations (including sklearn) is SIMPLS by de Jong (1993), "SIMPLS: An alternative approach to partial least squares regression". de Jong's algorithm computes PLS components without the iterative deflation step, making it both faster and numerically more stable.

The ISLR Connection

This tutorial is based on the lab exercise in James, Witten, Hastie & Tibshirani (2021), An Introduction to Statistical Learning, Chapter 6. ISLR provides an excellent treatment of PCR and PLS in the context of the bias-variance tradeoff, alongside Ridge and Lasso regression.

The Hitters dataset used here has become a standard benchmark for comparing regularisation and dimension reduction methods. With 19 correlated features, it sits in the sweet spot where these methods make a visible difference.

Further Reading

Try It Yourself

The interactive notebook includes exercises:

  1. Scree plot. Plot the explained variance per component and the cumulative curve. How many components do you need to capture 95% of the variance?
  2. PLS loadings. Compare the PLS weight vectors to the PCA loadings. Which features does PLS prioritise that PCA does not?
  3. Ridge vs PCR. Add a Ridge regression (with RidgeCV) to the comparison. In what sense is Ridge a "soft" version of PCR?
  4. Log-transform the target. Salary is right-skewed. Does predicting log⁡(Salary)\log(\text{Salary}) change which method wins?

Understanding PCR and PLS builds directly on linear regression and connects to Bayesian inference through the regularisation-as-prior interpretation. When the linear assumption breaks down, Gaussian process regression offers a non-parametric alternative that handles high-dimensional inputs gracefully.

Interactive Tools

  • PCA Visualizer: Drag a point cloud and watch the principal components, scree plot and explained variance follow, then project onto one component to see what the reduction discards.
  • Regression Playground: Fit and compare regression models interactively in the browser

Stay in the loop

Get notified when new tutorials and deep-dives are published. No spam, unsubscribe anytime.

Related Posts

Frequently Asked Questions