0

I am plotting receiver operating characteristics for 10-fold cross validation using matplotlib with following code: plt.rcParams["figure.figsize"] = (5,5)

for i1 in range(10):
    plt.plot(fpr_list[i1], tpr_list[i1], lw=1, alpha=0.3,label='ROC fold %d (AUC = %0.2f)' % (i1, aucs[i1]))
    plt.legend(bbox_to_anchor=(1.05, 1), loc=0)

plt.plot([0, 1], [0, 1], linestyle='--', lw=2, color='r',
         label='Mid Line', alpha=.8)

mean_tpr = np.mean(tprs, axis=0)
mean_tpr[-1] = 1.0
mean_auc = auc(mean_fpr, mean_tpr)
std_auc = np.std(aucs)
plt.plot(mean_fpr, mean_tpr, color='b',
         label=r'Mean ROC (AUC = %0.2f $\pm$ %0.2f)' % (mean_auc, std_auc),
         lw=2, alpha=.8)

std_tpr = np.std(tprs, axis=0)
tprs_upper = np.minimum(mean_tpr + std_tpr, 1)
tprs_lower = np.maximum(mean_tpr - std_tpr, 0)
plt.fill_between(mean_fpr, tprs_lower, tprs_upper, color='grey', alpha=.2,
                 label=r'$\pm$ 1 std. dev.')

plt.xlim([-0.05, 1.05])
plt.ylim([-0.05, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic')
plt.legend(bbox_to_anchor=(1.05, 1), loc=0)
plt.show()

fpr, tpr and other variables i got from my program. i got following image after running above codeenter image description here here roc values are not coming in picture. how to solve prlb

Hitesh
  • 1,285
  • 6
  • 20
  • 36
  • 1
    First create an axis, and plot the data on it. It can be done through `f, ax = plt.subplots(1,1)`. Then you can either use the function `subplots_adjust()` or you can retrieve the x0, y0, width, height parameter of the axis and then modify them. I don't have a python environment on this laptop, but I think someone could provide you an example. – Mathieu Aug 18 '18 at 16:47
  • thank you for quick reply, yup you are correct i am looking for example – Hitesh Aug 18 '18 at 16:48
  • `loc='best'` worked for me. and `draggable` legend is also good option. – Hitesh Aug 29 '18 at 07:57

0 Answers0