scikit-learn / scikit-learn/scikit-learn

Optimizing the fine-tuning of PCA / KernelPCA n_components

Open
#19,649 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

module:decomposition New Feature
Dominant language
Python
Stars
67.3k
Forks
27.4k
Avg merge
1d 15h
Merged PRs (30d)
58

Description

This example shows a way to use cross-validation to select the best value for n_components in the PCA:
https://scikit-learn.org/stable/tutorial/statistical_inference/putting_together.html

However, it seems that there would be a more computation-efficient way to do it, fitting the PCA only once with the maximum value of n_components tested, and then applying the transformation with different values of n_components.
Indeed, when using GridSearchCV to optimize n_components in the PCA, there is a new fit for each iteration.
As the PCA can be very slow, optimizing it would be cool.

Any idea on how to do it easily with current implementation of PCA and GridSearchCV ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked scikit-learn cross-validation tutorial and compare how PCA and KernelPCA interact with GridSearchCV when n_components varies. Determine whether fitting once at the maximum value can be supported without changing expected estimator behavior; done requires an agreed design and evidence that the optimization preserves correct cross-validation results.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.