Skip to content

Commit c84c33e

Browse files
icfaustjeremiedbb
andauthored
FIX Add input validation to _basePCA.inverse_transform (#29310)
Co-authored-by: Jérémie du Boisberranger <jeremie@probabl.ai>
1 parent 25aeaf3 commit c84c33e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Add input checks to the `inverse_transform` method of :class:`decomposition.PCA`
2+
and :class:`decomposition.IncrementalPCA`.
3+
:pr:`29310` by :user:`Ian Faust <icfaust>`.

sklearn/decomposition/_base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from ..base import BaseEstimator, ClassNamePrefixFeaturesOutMixin, TransformerMixin
1212
from ..utils._array_api import _add_to_diagonal, device, get_namespace
13-
from ..utils.validation import check_is_fitted, validate_data
13+
from ..utils.validation import check_array, check_is_fitted, validate_data
1414

1515

1616
class _BasePCA(
@@ -186,7 +186,11 @@ def inverse_transform(self, X):
186186
If whitening is enabled, inverse_transform will compute the
187187
exact inverse operation, which includes reversing whitening.
188188
"""
189-
xp, _ = get_namespace(X)
189+
xp, _ = get_namespace(X, self.components_, self.explained_variance_)
190+
191+
check_is_fitted(self)
192+
193+
X = check_array(X, input_name="X", dtype=[xp.float64, xp.float32])
190194

191195
if self.whiten:
192196
scaled_components = (

0 commit comments

Comments
 (0)