From b9625daa62df7e20ff103df42d87ba72af4b6e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavlin=20Poli=C4=8Dar?= Date: Fri, 7 Jun 2024 10:56:52 +0200 Subject: [PATCH] pca: override svd_solver to arpack when data is sparse and solver is set to auto --- Orange/projection/pca.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Orange/projection/pca.py b/Orange/projection/pca.py index d2b13d7e38a..a9ecb1cea94 100644 --- a/Orange/projection/pca.py +++ b/Orange/projection/pca.py @@ -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_))