MCPcopy Create free account
hub / github.com/ScottfreeLLC/AlphaPy / plot_roc_curve

Function plot_roc_curve

alphapy/plots.py:529–591  ·  view source on GitHub ↗

r"""Display ROC Curves with Cross-Validation. Parameters ---------- model : alphapy.Model The model object with plotting specifications. partition : alphapy.Partition Reference to the dataset. Returns ------- None : None References ----------

(model, partition)

Source from the content-addressed store, hash-verified

527#
528
529def plot_roc_curve(model, partition):
530 r"""Display ROC Curves with Cross-Validation.
531
532 Parameters
533 ----------
534 model : alphapy.Model
535 The model object with plotting specifications.
536 partition : alphapy.Partition
537 Reference to the dataset.
538
539 Returns
540 -------
541 None : None
542
543 References
544 ----------
545
546 http://scikit-learn.org/stable/modules/model_evaluation.html#receiver-operating-characteristic-roc
547
548 """
549
550 logger.info("Generating ROC Curves")
551 pstring = datasets[partition]
552
553 # For classification only
554
555 if model.specs['model_type'] != ModelType.classification:
556 logger.info('ROC Curves are for classification only')
557 return None
558
559 # Get X, Y for correct partition.
560
561 X, y = get_partition_data(model, partition)
562
563 # Initialize plot parameters.
564
565 plt.style.use('classic')
566 plt.figure()
567 lw = 2
568
569 # Plot a ROC Curve for each algorithm.
570
571 for algo in model.algolist:
572 logger.info("ROC Curve for Algorithm: %s", algo)
573 # compute ROC curve and ROC area for each class
574 probas = model.probas[(algo, partition)]
575 fpr, tpr, _ = roc_curve(y, probas)
576 roc_auc = auc(fpr, tpr)
577 plt.plot(fpr, tpr, lw=lw, label='%s (area = %0.2f)' % (algo, roc_auc))
578
579 # draw the luck line
580 plt.plot([0, 1], [0, 1], linestyle='--', color='k', label='Luck')
581 # define plot characteristics
582 plt.xlim([-0.05, 1.05])
583 plt.ylim([-0.05, 1.05])
584 plt.xlabel('False Positive Rate')
585 plt.ylabel('True Positive Rate')
586 title = BSEP.join([algo, "ROC Curve [", pstring, "]"])

Callers 1

generate_plotsFunction · 0.85

Calls 3

get_partition_dataFunction · 0.85
get_plot_directoryFunction · 0.85
write_plotFunction · 0.85

Tested by

no test coverage detected