'Plot ROC curve with y_label and y_pred both with binary values

here is a demo.

import numpy as np
from sklearn.metrics import roc_curve, roc_auc_score
import matplotlib.pyplot as plt

y = np.array([1] * 3 + [0] * 70)
scores = np.array([1] * 13 + [0] * 60)
fpr, tpr, thresholds = roc_curve(y, scores)

plt.subplots(1, figsize=(10,10))
plt.plot(fpr, tpr)
plt.show()

Here is the figure. ROC

It's not similar to what we saw as usual like usual ROC curve

So I wondered is there anything wrong that I did.

The application scenario is I have a multi-channel signals. I calculated a feature across channels, then I'll have a value(between 0 to 1) for each channel.
If the value is > 0.2, then it should be class 1, else 0.

Is there anyway that I could make the ROC curve more resonable?



Solution 1:[1]

In the ROC curve the threshold varies dynamically from 0 to 1 and is not set fix to 0.2 like you discribed. For each value of the threshold the Recall and Precision metric is the x and y value of the curve. You get the desired curve if you provide not binary predictions but probabilities, so the prodictions should lie in the range [0, 1].
If your predictions come from scikit-learn you should use predict_proba instead of predict.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex G