Plotting a ROC curve in scikit yields only 3 points

how to plot roc curve in matplotlib
plot multiple roc curves python
sklearn roc curve
roc curve from scratch python
roc curve interpretation
roc curve logistic regression
plot roc curve pyspark
plot roc auc graph

TLDR: scikit's roc_curve function is only returning 3 points for a certain dataset. Why could this be, and how do we control how many points to get back?

I'm trying to draw a ROC curve, but consistently get a "ROC triangle".

lr = LogisticRegression(multi_class = 'multinomial', solver = 'newton-cg')
y = data['target'].values
X = data[['feature']].values

model =,y)

# get probabilities for clf
probas_ = model.predict_log_proba(X)

Just to make sure the lengths are ok:

print len(y)
print len(probas_[:, 1])

Returns 13759 on both.

Then running:

false_pos_rate, true_pos_rate, thresholds = roc_curve(y, probas_[:, 1])
print false_pos_rate

returns [ 0. 0.28240129 1. ]

If I call threasholds, I get array([ 0.4822225 , -0.5177775 , -0.84595197]) (always only 3 points).

It is therefore no surprise that my ROC curve looks like a triangle.

What I cannot understand is why scikit's roc_curve is only returning 3 points. Help hugely appreciated.

The number of points depend on the number of unique values in the input. Since the input vector has only 2 unique values, the function gives correct output.

Receiver Operating Characteristic (ROC), This means that the top left corner of the plot is the “ideal” point - a false from sklearn import svm, datasets from sklearn.metrics import roc_curve, auc from First aggregate all false positive rates all_fpr = np.unique(np.concatenate([fpr[i] for i 

I had the same problem with a different example. The mistake I made was to input the outcomes for a given threshold and not the probabilities in the argument y_score of roc_curve. It also gives a plot with three points but it is a mistake !

Plot ROC Curve for Binary Classification with Matplotlib, In ROC (Receiver operating characteristic) curve, true positive rates are /​30051284/plotting-a-roc-curve-in-scikit-yields-only-3-points, the 

It's not necessary to get 1 point except (0,0) and (1,1). I'm using mushrooms dataset from kaggle for a binary classification problem. Procuring fpr and tpr from roc_curve, I'm getting 4 more points, though their value is more or less same.

fpr = {0, 0, 0.02290076, 0.0267176, 0.832061, 1}

tpr = {0, 0.0315361, 0.985758, 0.996948, 1, 1}

I'm not sure if we can consider this as 1 point because plotting the curve using this looks like the one shown in question.

Drawing ROC Curve, Figure 3. Example of ROC curve. The following code snippet shows how to calculate the true positive and false positive rates for the plot shown 

I ran into same problem, and after reading the documentaion carefully I realized that the mistake is in:

probas_ = model.predict_log_proba(X)

Although, there were hints pointed by others by checking the uniqueness. It should be instead:

probas_ = model.decisions(X)

How to Use ROC Curves and Precision-Recall Curves for , A model with no skill is represented at the point (0.5, 0.5). We can plot a ROC curve for a model in Python using the roc_curve() scikit-learn function. The function returns the false positive rates for each threshold, true positive rates for 3 # calculate precision-recall curve. precision, recall, thresholds 

How can I draw a ROC curve having TP Rate and FP Rate Values?, To draw a ROC curve, only the true positive rate (TPR) and false positive rate yield a point in the upper left corner or coordinate (0,1) of the ROC space, http://​ Today I got to know that this question has caught a lot of attention during the last three years.

ROC Curve explained using a COVID-19 hypothetical example , I use a COVID-19 example to make my point and I also speak about the confusion matrix. Finally, I provide Python code for plotting the ROC and confusion matrix from The ROC curve is only defined for binary classification problems. For example, if we have N=3 classes then we will need to define the​ 

sklearn.metrics.roc_curve Python Example, This page provides Python code examples for sklearn.metrics.roc_curve. plot: :​return: """ fpr, tpr, _ = roc_curve(y_true, y_pred) auc_score = auc(fpr, tpr) if def show_roc_curve(self, save=False): """ Plots the ROC curve to see True and the case where there are two points with the same minimum distance, return only the​ 

  • Did you check the values in probas_[:,1]? Although it has length of 13759, it may only contain 3 values...
  • Thank you for your help, I did [print pd.Series(probas_[:,1]).unique()], and indeed only 2 uniques ([-0.84595197 -0.5177775 ]) were returned
  • Glad it helps. Please accept the answer if you like.