Skip to content

Function r2_score from sklearn.metrics Fails #30484

Closed Answered by lesteve
minoush82 asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry you got caught by a scikit-learn issue in the latest release when using a scikit-learn metric on PyTorch tensors on the CPU and the error is confusing, see #29107 (comment) for more details.

For completeness if you want a tensor on the GPU you need to use device='cuda' I think:

X = torch.rand((1000,2), device='cuda')

If you want to fix your error quickly you need to convert to numpy arrays before calling the scikit-learn metric, something like arr.numpy() if you array in on the CPU or arr.cpu().device().

You may be interested to have a look at array API support which is an ongoing work.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by lesteve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants