how I get different array size in calculating tpr?

while learning about ROC curves I got confused by the how these are made.

I am considering here the Iris flower classification problem. To calculate TPR we can use $$TPR=\frac{True \ positive}{True\ positive + \ False \ Negative }$$ Now in this case first we feed in the test data and find out the TPR and FPR by using the formulas above.But in this case how we get different array size.

>>>fpr = dict()
>>>tpr = dict()
>>>roc_auc = dict()
>>>for i in range(n_classes):
fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])
roc_auc[i] = auc(fpr[i], tpr[i])

tpr(true positive rate)
0: array([ 0.04761905,  1.        ,  1.        ]),  1: array([
0.03333333,  0.03333333,  0.1       ,  0.1       ,  0.2       ,
0.2       ,  0.23333333,  0.23333333,  0.36666667,  0.36666667,
0.4       ,  0.4       ,  0.7       ,  0.7       ,  0.73333333,
0.73333333,  0.76666667,  0.76666667,  0.8       ,  0.8       ,
0.83333333,  0.83333333,  0.86666667,  0.86666667,  0.9       ,
0.9       ,  0.93333333,  0.93333333,  0.96666667,  0.96666667,
1.        ,  1.        ]),  2: array([ 0.04166667,  0.79166667,  0.79166667,  0.95833333,  0.95833333,
1.        ,  1.        ]),


1 Answer

You get different array sizes for your different classes because the number of points in your ROC curve depends on the number of unique predictions.

If your model only predicts 0, .5, and 1 your ROC curve will have three points. If your model predicts 100 different probabilities, your ROC curve will have ~100 points. (In practice, the length of the ROC curve may have a couple extra points where the points (0,0) and (1,1) are appended.

If you look at np.unique(y_score[:,i]).size for different i you should see the differences.