Skip to content

Commit 0a51cd2

Browse files
committed
n_components in PCA has to be greater than zero
1 parent 4c549ad commit 0a51cd2

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

pyvisim/encoders/_base_encoder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,12 @@ def learn(
457457
print(" - Feature Extractor used:", self.feature_extractor.__class__.__name__)
458458
print(" - Dimension of the feature space:", feat_dim := features.shape[1])
459459
if dim_reduction_factor:
460-
self._pca = PCA(n_components=feat_dim // dim_reduction_factor)
460+
if (n_components := feat_dim // dim_reduction_factor) <= 0:
461+
raise ValueError(
462+
f"dim_reduction_factor {dim_reduction_factor} is too large for the feature dimension {feat_dim}. "
463+
f"Resulting PCA components would be {n_components}. Please choose a smaller dim_reduction_factor."
464+
)
465+
self._pca = PCA(n_components=n_components)
461466
if self._pca is not None:
462467
if not self._pca.is_fitted:
463468
self._pca.fit(features)

0 commit comments

Comments
 (0)