Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for sklearn 1.5 #3047

Merged
merged 6 commits into from
May 10, 2024
Merged

Fixes for sklearn 1.5 #3047

merged 6 commits into from
May 10, 2024

Conversation

flying-sheep
Copy link
Member

@flying-sheep flying-sheep commented May 7, 2024

Scikit-learn 1.5.0 will no longer have issparse exported, so let’s import it from where it belongs

@flying-sheep flying-sheep added this to the 1.10.2 milestone May 7, 2024
@flying-sheep flying-sheep enabled auto-merge (squash) May 7, 2024 08:09
Copy link

codecov bot commented May 7, 2024

Codecov Report

Attention: Patch coverage is 76.47059% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 73.90%. Comparing base (9714250) to head (d314182).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3047      +/-   ##
==========================================
- Coverage   73.98%   73.90%   -0.08%     
==========================================
  Files         117      117              
  Lines       12795    12763      -32     
==========================================
- Hits         9466     9433      -33     
- Misses       3329     3330       +1     
Files Coverage Δ
scanpy/_utils/__init__.py 66.66% <100.00%> (ø)
scanpy/datasets/_utils.py 100.00% <100.00%> (ø)
scanpy/preprocessing/_utils.py 92.10% <100.00%> (ø)
scanpy/testing/_pytest/fixtures/data.py 100.00% <ø> (ø)
scanpy/testing/_pytest/marks.py 100.00% <100.00%> (ø)
scanpy/tools/_ingest.py 77.23% <100.00%> (ø)
scanpy/tools/_tsne.py 93.02% <100.00%> (ø)
scanpy/external/pp/_magic.py 25.00% <50.00%> (ø)
scanpy/tools/_louvain.py 21.42% <50.00%> (ø)
scanpy/_compat.py 74.00% <60.00%> (ø)
... and 2 more

... and 11 files with indirect coverage changes

@flying-sheep
Copy link
Member Author

flying-sheep commented May 7, 2024

Hmm, seems like PCA with svd_solver='arpack' works differently in sklearn 1.5 and flips the coordinates in some tests:

scikit-learn/scikit-learn#28826

E.g. this used to work, now it doesn’t.

from __future__ import annotations

import numpy as np
from sklearn.decomposition import PCA

data = np.asarray([[-1, 2, 0], [3, 4, 0], [1, 2, 0]]).T
expected = np.array(
    [[-1.579575e-15, 1.490712], [-2.44949, -0.745356], [2.44949, -0.745356]],
    dtype=np.float32,
)

pca = PCA(n_components=2, svd_solver="arpack", random_state=np.random.RandomState(0))
transformed = pca.fit_transform(data).astype(np.float32)
np.testing.assert_almost_equal(transformed, expected, decimal=5)

@flying-sheep flying-sheep changed the title Fix import of issparse Fixes for sklearn 1.5 May 10, 2024
@flying-sheep flying-sheep merged commit d2a5368 into main May 10, 2024
14 checks passed
@flying-sheep flying-sheep deleted the fix-issparse branch May 10, 2024 13:43
meeseeksmachine pushed a commit to meeseeksmachine/scanpy that referenced this pull request May 10, 2024
flying-sheep added a commit that referenced this pull request May 10, 2024
Co-authored-by: Philipp A <flying-sheep@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant