Skip to content

Commit

Permalink
pca: override svd_solver to arpack when data is sparse and solver is …
Browse files Browse the repository at this point in the history
…set to auto
  • Loading branch information
pavlin-policar committed Jun 7, 2024
1 parent 16fa88e commit b9625da
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Orange/projection/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def fit(self, X, Y=None):
if sp.issparse(X) and params["n_components"] == min(X.shape):
X = X.toarray()

# In scikit-learn==1.4.0, only the arpack solver is supported for sparse
# data and `svd_solver="auto"` doesn't auto-resolve to this. This is
# fixed in scikit-learn 1.5.0, but for the time being, override these
# settings here
if sp.issparse(X) and params["svd_solver"] == "auto":
params["svd_solver"] = "arpack"

proj = self.__wraps__(**params)
proj = proj.fit(X, Y)
return PCAModel(proj, self.domain, len(proj.components_))
Expand Down

0 comments on commit b9625da

Please sign in to comment.