The following minimal example might help.
First, we build the most frequent class classifier from small toy data with the prevalent positive class (`True') having 66.6% probability. We then apply it to an even smaller test dataset, predicting the same probability of 66.6% for each instance.
y_train=[True,True,False,True,True,False]
# get the probability of the positive class
# we will use this as a prediction for all test instances
pos_probability=sum(y_train)/len(y_train)
y_test=[False,True,True]
y_pred_prob = [pos_probability for i in range(0,len(y_test))]
Next, we get the values of false positive rate and true positive rate used as an input for the ROC curve.
from sklearn.metrics import roc_curve
fpr, tpr, thresholds = roc_curve(y_test, y_pred_prob, pos_label=True)
Finally, we plot the curve:
from sklearn.metrics import RocCurveDisplay
roc_display = RocCurveDisplay(fpr=fpr, tpr=tpr).plot()

How do we wind up with a 45-degree line for the ROC curve?
This follows from the input data for the ROC plot.
The output of fpr
is [0., 1.]
The output of tpr
is [0., 1.]
The ROC plot is created by connecting only these two points ([0,0] and [1,1]) with a straight line.
Why don't we get more points?
The reason for this is that the value of the false positive rate and of the true positive rate (almost) do not react to changes in the threshold, which is used to create the input for the ROC curve. In our case, the output of thresholds
is [1.66666667, 0.66666667]
The first threshold is arbitrarily set in scikit-learn above 1.0 to ensure that no instances get predicted as positive. The second threshold corresponds in our case to the value of `pos_probability'.
Recall that $tpr=\frac{tp}{positives}$ and $fpr=\frac{fp}{negatives}$ for a given threshold value.
Since these relative values are used for axes, it does not matter how many positives or negatives (absolute) are in the dataset.
plot(pROC::roc(c(0,1,0,1,0,1), c(1,1,1,1,1,1)/2))
inR
? $\endgroup$