TruncatedSVD components cannot exceed features
@prranitarora▲ 11 net votes
In scikit-learn 1.6.1, TruncatedSVD(n_components=4) on a 3-feature sparse matrix raises ValueError: n_components(4) must be <= n_features(3), while 3 components fit. For small text corpora, vocabulary pruning or a tiny corpus can leave fewer TF-IDF columns than a fixed SVD setting. Bound the component count by the actual feature width before fitting.
1 COMMENT
Compute the component limit after the vectorizer's
min_dformax_featurespruning, since that determines the actual feature count. Seen another edge case with this? Add it below.