question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unable to use wandb.plots.ROC

See original GitHub issue

wandb --version && python --version && uname

  • Weights and Biases version: 0.8.35
  • Python version: 3.7.6
  • Operating System: Linux

Description

I’m trying to use wandb.plots.ROC to plot a ROC curve for a two-class classification problem. I’m executing it just like in this example:

wandb.log({'roc': wandb.plots.ROC(y_true, y_probas, labels)})

What I Did

In my case, y_true has shape (n, ) and y_probas also has shape (n, ).

Each element of y_true is an int (0 or 1), and each element of y_probas is the predicted probability in range (0, 1). I’m also using labels=['class 1', 'class 2']

But I’m getting this error message:

Traceback (most recent call last):
  File "teacher.py", line 407, in <module>
    training_history = train(config, vox, d, predictor, label_out)
  File "teacher.py", line 258, in train
    wandb.log({'ROC': wandb.plots.ROC(y, y_preds, lb)})
  File "/home/mpds/miniconda3/envs/docktdeep/lib/python3.7/site-packages/wandb/plots/roc.py", line 71, in roc
    return roc_table(fpr_dict, tpr_dict, classes, indices_to_plot)
  File "/home/mpds/miniconda3/envs/docktdeep/lib/python3.7/site-packages/wandb/plots/roc.py", line 50, in roc_table
    fpr_dict[i], tpr_dict[i], _ = roc_curve(y_true, probas[:, i],
IndexError: too many indices for array

It seems that what is causing the error is this statement: probas[:, i].

In the docs it’s written (without mention to what shape these should be):

y_true (arr): Test set labels.
y_probas (arr): Test set predicted probabilities.

I’ve looked into the source code and examples, but I wasn’t able to understand what shape is expected of probas for the binary classification case.

Thanks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
lavanyashuklacommented, Jun 1, 2020

Hi, sorry the docs aren’t clear! This is the expected format –

y_test:  [1 1 0 1 1 1 1 0 0 1 1 1 1 1 1]
y_probas:  [[0. 1.]
 [0. 1.]
 [1. 0.]
 [0. 1.]
 [0. 1.]
 [0. 1.]
 [0. 1.]
 [1. 0.]
 [1. 0.]
 [0. 1.]
 [0. 1.]
 [0. 1.]
 [0. 1.]
 [0. 1.]
 [0. 1.]]
labels:  ['setosa' 'versicolor' 'virginica']

I also added a complete working example for you.

2reactions
ramit-wandbcommented, Jan 13, 2022

Hey @sngyo,

You are right. wandb.plot.roc_curve expects the probabilities of both classes as input, so y_score will need to be transformed to [[0.6, 0.4], [0.3, 0.7], [0.2, 0.8]].

Thanks, Ramit

Read more comments on GitHub >

github_iconTop Results From Across the Web

unable to use wandb.plots.ROC · Issue #1076
I'm trying to use wandb.plots.ROC to plot a ROC curve for a two-class classification problem. I'm executing it just like in this example:....
Read more >
Plot ROC Curves With Weights & Biases
This article provides usage and examples for plotting ROC curves with Weights & Biases using wandb.plot.roc_curve().
Read more >
How to use StratifiedKFold with wandb sweeps?
The solution requires some contortions for the wandb library to spawn multiple jobs on behalf of a launched sweep job. The basic idea...
Read more >
wandb Changelog
- Extend wandb.plots.feature_importances to work with more model types, thanks neomatrix369! :bug: Bug Fix - Code saving for jupyter notebooks restored
Read more >
Visualization of Sklearn Model Part1 : Weight And Biases
W&B has a method called regression plot when we use this we can plot all ... wandb.sklearn.plot_roc(y_test, y_probas, labels) = ROC
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found