watex.view.EvalPlot.plotROC#

EvalPlot.plotROC(clfs, label, method=None, cvp_kws=None, **roc_kws)[source]#

Plot receiving operating characteric (ROC) classifiers.

Can plot multiple classifiers at once. If multiple classifiers are given, each classifier must be a tuple of ( <name>, classifier>, <method>). For instance, to plot the both sklearn.ensemble.RandomForestClassifier and sklearn.linear_model.SGDClassifier classifiers, they must be ranged as follow:

clfs =[
    ('sgd', SGDClassifier(), "decision_function" ),
    ('forest', RandomForestClassifier(), "predict_proba")
    ]

It is important to know whether the method ‘predict_proba’ is valid for the scikit-learn classifier, we want to plot its ROC curve.

Parameters:
  • clfs (callables, always as a function, classifier estimators) – A supervised predictor with a finite set of discrete possible output values. A classifier must supports modeling some of binary, targets. It must store a classes attribute after fitting.

  • label (int,) – Specific class to evaluate the tradeoff of precision and recall. label needs to be specified and a value within the target.

  • kind (str, ['threshold|'recall'], default='threshold') – kind of PR plot. If kind is ‘recall’, method plots the precision VS the recall scores, otherwiwe the PR tradeoff is plotted against the ‘threshold.’

  • method (str) – Method to get scores from each instance in the trainset. Could be decison_funcion or predict_proba. When using the scikit-Learn classifier, it generally has one of the method. Default is decision_function.

  • cvp_kws (dict, optional) – The sklearn.model_selection.cross_val_predict() keywords additional arguments

  • prt_kws (dict,) – Additional keyword arguments passed to func:watex.exlib.sklearn.precision_recall_tradeoff

  • roc_kws (dict) – roc_curve additional keywords arguments.

Returns:

``self``self for easy method chaining.

Return type:

EvalPlot instance

Examples

  1. Plot ROC for single classifier

>>> from watex.exlib.sklearn import ( SGDClassifier,
                                     RandomForestClassifier
                                     )
>>> from watex.datasets.dload import load_bagoue
>>> from watex.utils import cattarget
>>> from watex.view.mlplot import EvalPlot
>>> X , y = load_bagoue(as_frame =True )
>>> sgd_clf = SGDClassifier(random_state= 42) # our estimator
>>> b= EvalPlot(scale = True , encode_labels=True)
>>> b.fit_transform(X, y)
>>> # binarize the label b.y
>>> ybin = cattarget(b.y, labels= 2 ) # can also use labels =[0, 1]
>>> b.y = ybin
>>> # plot the ROC
>>> b.plotROC(sgd_clf , label =1) # class=1
... EvalPlot(tname= None, objective= None, scale= True, ... ,
             sns_height= 4.0, sns_aspect= 0.7, verbose= 0)

(2)-> Plot ROC for multiple classifiers

>>> b= EvalPlot(scale = True , encode_labels=True,
                lw =3., lc=(.9, 0, .8), font_size=7 )
>>> sgd_clf = SGDClassifier(random_state= 42)
>>> forest_clf =RandomForestClassifier(random_state=42)
>>> b.fit_transform(X, y)
>>> # binarize the label b.y
>>> ybin = cattarget(b.y, labels= 2 ) # can also use labels =[0, 1]
>>> b.y = ybin
>>> clfs =[('sgd', sgd_clf, "decision_function" ),
       ('forest', forest_clf, "predict_proba")]
>>> b.plotROC (clfs =clfs , label =1 )
... EvalPlot(tname= None, objective= None, scale= True, ... ,
             sns_height= 4.0, sns_aspect= 0.7, verbose= 0)