@@ -175,6 +175,8 @@ def plot_confusion_matrix(y_true, y_pred, labels=None, true_labels=None,
175175 return ax
176176
177177
178+ @deprecated ('This will be removed in v0.5.0. Please use '
179+ 'scikitplot.metrics.plot_roc instead.' )
178180def plot_roc_curve (y_true , y_probas , title = 'ROC Curves' ,
179181 curves = ('micro' , 'macro' , 'each_class' ),
180182 ax = None , figsize = None , cmap = 'nipy_spectral' ,
@@ -322,6 +324,138 @@ def plot_roc_curve(y_true, y_probas, title='ROC Curves',
322324 return ax
323325
324326
327+ def plot_roc (y_true , y_probas , title = 'ROC Curves' ,
328+ plot_micro = True , plot_macro = True , classes_to_plot = None ,
329+ ax = None , figsize = None , cmap = 'nipy_spectral' ,
330+ title_fontsize = "large" , text_fontsize = "medium" ):
331+ """Generates the ROC curves from labels and predicted scores/probabilities
332+
333+ Args:
334+ y_true (array-like, shape (n_samples)):
335+ Ground truth (correct) target values.
336+
337+ y_probas (array-like, shape (n_samples, n_classes)):
338+ Prediction probabilities for each class returned by a classifier.
339+
340+ title (string, optional): Title of the generated plot. Defaults to
341+ "ROC Curves".
342+
343+ plot_micro (boolean, optional): Plot the micro average ROC curve.
344+ Defaults to ``True``.
345+
346+ plot_macro (boolean, optional): Plot the macro average ROC curve.
347+ Defaults to ``True``.
348+
349+ classes_to_plot (list-like, optional): Classes for which the ROC
350+ curve should be plotted. e.g. [0, 'cold']. If given class does not exist,
351+ it will be ignored. If ``None``, all classes will be plotted. Defaults to
352+ ``None``
353+
354+ ax (:class:`matplotlib.axes.Axes`, optional): The axes upon which to
355+ plot the curve. If None, the plot is drawn on a new set of axes.
356+
357+ figsize (2-tuple, optional): Tuple denoting figure size of the plot
358+ e.g. (6, 6). Defaults to ``None``.
359+
360+ cmap (string or :class:`matplotlib.colors.Colormap` instance, optional):
361+ Colormap used for plotting the projection. View Matplotlib Colormap
362+ documentation for available options.
363+ https://matplotlib.org/users/colormaps.html
364+
365+ title_fontsize (string or int, optional): Matplotlib-style fontsizes.
366+ Use e.g. "small", "medium", "large" or integer-values. Defaults to
367+ "large".
368+
369+ text_fontsize (string or int, optional): Matplotlib-style fontsizes.
370+ Use e.g. "small", "medium", "large" or integer-values. Defaults to
371+ "medium".
372+
373+ Returns:
374+ ax (:class:`matplotlib.axes.Axes`): The axes on which the plot was
375+ drawn.
376+
377+ Example:
378+ >>> import scikitplot as skplt
379+ >>> nb = GaussianNB()
380+ >>> nb = nb.fit(X_train, y_train)
381+ >>> y_probas = nb.predict_proba(X_test)
382+ >>> skplt.metrics.plot_roc(y_test, y_probas)
383+ <matplotlib.axes._subplots.AxesSubplot object at 0x7fe967d64490>
384+ >>> plt.show()
385+
386+ .. image:: _static/examples/plot_roc_curve.png
387+ :align: center
388+ :alt: ROC Curves
389+ """
390+ y_true = np .array (y_true )
391+ y_probas = np .array (y_probas )
392+
393+ classes = np .unique (y_true )
394+ probas = y_probas
395+
396+ if classes_to_plot is None :
397+ classes_to_plot = classes
398+
399+ if ax is None :
400+ fig , ax = plt .subplots (1 , 1 , figsize = figsize )
401+
402+ ax .set_title (title , fontsize = title_fontsize )
403+
404+ fpr_dict = dict ()
405+ tpr_dict = dict ()
406+
407+ indices_to_plot = np .in1d (classes , classes_to_plot )
408+ for i , to_plot in enumerate (indices_to_plot ):
409+ fpr_dict [i ], tpr_dict [i ], _ = roc_curve (y_true , probas [:, i ],
410+ pos_label = classes [i ])
411+ if to_plot :
412+ roc_auc = auc (fpr_dict [i ], tpr_dict [i ])
413+ color = plt .cm .get_cmap (cmap )(float (i ) / len (classes ))
414+ ax .plot (fpr_dict [i ], tpr_dict [i ], lw = 2 , color = color ,
415+ label = 'ROC curve of class {0} (area = {1:0.2f})'
416+ '' .format (classes [i ], roc_auc ))
417+
418+ if plot_micro :
419+ binarized_y_true = label_binarize (y_true , classes = classes )
420+ if len (classes ) == 2 :
421+ binarized_y_true = np .hstack (
422+ (1 - binarized_y_true , binarized_y_true ))
423+ fpr , tpr , _ = roc_curve (binarized_y_true .ravel (), probas .ravel ())
424+ roc_auc = auc (fpr , tpr )
425+ ax .plot (fpr , tpr ,
426+ label = 'micro-average ROC curve '
427+ '(area = {0:0.2f})' .format (roc_auc ),
428+ color = 'deeppink' , linestyle = ':' , linewidth = 4 )
429+
430+ if plot_macro :
431+ # Compute macro-average ROC curve and ROC area
432+ # First aggregate all false positive rates
433+ all_fpr = np .unique (np .concatenate ([fpr_dict [x ] for x in range (len (classes ))]))
434+
435+ # Then interpolate all ROC curves at this points
436+ mean_tpr = np .zeros_like (all_fpr )
437+ for i in range (len (classes )):
438+ mean_tpr += interp (all_fpr , fpr_dict [i ], tpr_dict [i ])
439+
440+ # Finally average it and compute AUC
441+ mean_tpr /= len (classes )
442+ roc_auc = auc (all_fpr , mean_tpr )
443+
444+ ax .plot (all_fpr , mean_tpr ,
445+ label = 'macro-average ROC curve '
446+ '(area = {0:0.2f})' .format (roc_auc ),
447+ color = 'navy' , linestyle = ':' , linewidth = 4 )
448+
449+ ax .plot ([0 , 1 ], [0 , 1 ], 'k--' , lw = 2 )
450+ ax .set_xlim ([0.0 , 1.0 ])
451+ ax .set_ylim ([0.0 , 1.05 ])
452+ ax .set_xlabel ('False Positive Rate' , fontsize = text_fontsize )
453+ ax .set_ylabel ('True Positive Rate' , fontsize = text_fontsize )
454+ ax .tick_params (labelsize = text_fontsize )
455+ ax .legend (loc = 'lower right' , fontsize = text_fontsize )
456+ return ax
457+
458+
325459def plot_ks_statistic (y_true , y_probas , title = 'KS Statistic Plot' ,
326460 ax = None , figsize = None , title_fontsize = "large" ,
327461 text_fontsize = "medium" ):
@@ -554,7 +688,7 @@ def plot_precision_recall(y_true, y_probas,
554688 "Precision-Recall curve".
555689
556690 plot_micro (boolean, optional): Plot the micro average ROC curve.
557- Defaults to `True`.
691+ Defaults to `` True` `.
558692
559693 classes_to_plot (list-like, optional): Classes for which the precision-recall
560694 curve should be plotted. e.g. [0, 'cold']. If given class does not exist,
0 commit comments