Custom Tooltip

Hello!

I am trying to plot a ROC curve and is working nicely! Now I want to modify the tooltip to add the Threshold value. I think that can be done with Weave and the Table of Thresholds, False and True Positive Rates but I don’t have too much knowledge about Weave.

Example run with Plot and Table: Weights & Biases

Weave expression here (at Tooltip field)?

The code I used to generate the tables:

def roc_curve_multilabel(
    y_true=None, y_probas=None, labels=None, title=None
):
    y_true = np.array(y_true)
    y_probas = np.array(y_probas)
    
    classes = np.arange(0, y_true.shape[1])
    
    fpr, tpr, thr = dict(), dict(), dict()
    
    for c in classes:
        if labels is not None and (
            isinstance(classes[c], int) or isinstance(classes[0], np.integer)
        ):
            class_label = labels[classes[c]]
        else:
            class_label = classes[c]
        fpr[class_label], tpr[class_label], thr[class_label] = sklearn_metrics.roc_curve(
            y_true[..., c], y_probas[..., c]
        )
    
    df = pd.DataFrame(
        {
            "class": np.hstack([[k] * len(v) for k, v in fpr.items()]),
            "fpr": np.hstack(list(fpr.values())),
            "tpr": np.hstack(list(tpr.values())),
            "thr": np.hstack(list(thr.values())),
        }
    )
    
    df = df.round(3)

    if len(df) > wandb.Table.MAX_ROWS:
        wandb.termwarn(
            "wandb uses only %d data points to create the plots." % wandb.Table.MAX_ROWS
        )
        # different sampling could be applied, possibly to ensure endpoints are kept
        df = sklearn_utils.resample(
            df,
            replace=False,
            n_samples=wandb.Table.MAX_ROWS,
            random_state=42,
            stratify=df["class"],
        ).sort_values(["fpr", "tpr", "class"])

    table = wandb.Table(dataframe=df)
    title = title or "ROC"
    return wandb.plot_table(
        "wandb/area-under-curve/v0",
        table,
        {"x": "fpr", "y": "tpr", "class": "class"},
        {
            "title": title,
            "x-axis-title": "False positive rate",
            "y-axis-title": "True positive rate",
        },
    )
1 Like

Hi @marioparreno, it looks like this is a bug affecting just line plots in Weave. The tooltip expression should be row["thr"] but this isn’t currently working with line plots. If you change the mark to “point” you will get the expected behavior. I’ve reported this to our engineering team so we can get a fix on this.

Screen Shot 2023-01-27 at 3.47.59 PM

Screen Shot 2023-01-27 at 3.47.48 PM

Hi @nathank , thanks! In the meantime could you help me with something related?

At the tooltip I would like to put more info, as the fpr, tpr and class. I can add expressions simply with ‘+’, but I want to add new lines. I tried ‘\n’ and ‘
’ but not works. Examples:

row["fpr"].toString.prepend("FPR: ") + "\n" + row["thr"].toString.prepend("Threshold: ")

I understand the ‘
’ is not treated as HTML but with ‘\n’ something strange occurs too, the tooltip is just ‘-’.

err

Hello @nathank, sorry for the ping, but do we have any advance? :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.