Skip to content

Commit

Permalink
pca: avoid "AttributeError: can't set attribute" in ImprovedPCA
Browse files Browse the repository at this point in the history
n_features_ attribute of decomposition.PCA is deprecated in favor of n_features_in_
  • Loading branch information
JakaKokosar committed Mar 31, 2023
1 parent e8067c3 commit b7c3266
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Orange/projection/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ class ImprovedPCA(skl_decomposition.PCA):
# pylint: disable=too-many-branches
def _fit(self, X):
"""Dispatch to the right submethod depending on the chosen solver."""
X = check_array(
X = self._validate_data(
X,
accept_sparse=["csr", "csc"],
dtype=[np.float64, np.float32],
ensure_2d=True,
copy=self.copy,
reset=False,
accept_sparse=["csr", "csc"],
copy=self.copy
)

# Handle n_components==None
Expand Down Expand Up @@ -201,7 +201,7 @@ def _fit_truncated(self, X, n_components, svd_solver):
random_state=random_state,
)

self.n_samples_, self.n_features_ = n_samples, n_features
self.n_samples_ = n_samples
self.components_ = V
self.n_components_ = n_components

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

X = check_array(
X = self._validate_data(
X,
accept_sparse=["csr", "csc"],
dtype=[np.float64, np.float32],
ensure_2d=True,
copy=self.copy,
reset=False,
copy=self.copy
)

if self.mean_ is not None:
Expand Down

0 comments on commit b7c3266

Please sign in to comment.