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 bothsklearn.ensemble.RandomForestClassifierandsklearn.linear_model.SGDClassifierclassifiers, 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_funcionorpredict_proba. When using the scikit-Learn classifier, it generally has one of the method. Default isdecision_function.cvp_kws (dict, optional) – The
sklearn.model_selection.cross_val_predict()keywords additional argumentsprt_kws (dict,) – Additional keyword arguments passed to func:watex.exlib.sklearn.precision_recall_tradeoff
roc_kws (dict) – roc_curve additional keywords arguments.
- Returns
``self`` –
selffor easy method chaining.- Return type
EvalPlot instance
Examples
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)