Skip to content

Commit a823c86

Browse files
JakaKokosarmarkotoplak
authored andcommitted
pca: avoid "AttributeError: can't set attribute" in ImprovedPCA
n_features_ attribute of decomposition.PCA is deprecated in favor of n_features_in_
1 parent e88fc32 commit a823c86

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Orange/projection/pca.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ class ImprovedPCA(skl_decomposition.PCA):
9999
# pylint: disable=too-many-branches
100100
def _fit(self, X):
101101
"""Dispatch to the right submethod depending on the chosen solver."""
102-
X = check_array(
102+
X = self._validate_data(
103103
X,
104-
accept_sparse=["csr", "csc"],
105104
dtype=[np.float64, np.float32],
106-
ensure_2d=True,
107-
copy=self.copy,
105+
reset=False,
106+
accept_sparse=["csr", "csc"],
107+
copy=self.copy
108108
)
109109

110110
# Handle n_components==None
@@ -201,7 +201,7 @@ def _fit_truncated(self, X, n_components, svd_solver):
201201
random_state=random_state,
202202
)
203203

204-
self.n_samples_, self.n_features_ = n_samples, n_features
204+
self.n_samples_ = n_samples
205205
self.components_ = V
206206
self.n_components_ = n_components
207207

@@ -221,12 +221,12 @@ def _fit_truncated(self, X, n_components, svd_solver):
221221
def transform(self, X):
222222
check_is_fitted(self, ["mean_", "components_"], all_or_any=all)
223223

224-
X = check_array(
224+
X = self._validate_data(
225225
X,
226226
accept_sparse=["csr", "csc"],
227227
dtype=[np.float64, np.float32],
228-
ensure_2d=True,
229-
copy=self.copy,
228+
reset=False,
229+
copy=self.copy
230230
)
231231

232232
if self.mean_ is not None:

0 commit comments

Comments
 (0)