watex.view.plotModel#

watex.view.plotModel(yt, ypred=None, *, clf=None, Xt=None, predict=False, prefix=None, index=None, fill_between=False, labels=None, return_ypred=False, **baseplot_kws)[source]#
Plot model ‘y’ (true labels) versus ‘ypred’ (predicted) from test

data.

Plot will allow to know where estimator/classifier fails to predict correctly the target

Parameters
yt:array-like, shape (M, ) ``M=m-samples``,

test target; Denotes data that may be observed at training time as the dependent variable in learning, but which is unavailable at prediction time, and is usually the target of prediction.

ypred:array-like, shape (M, ) ``M=m-samples``

Array of the predicted labels. It has the same number of samples as the test data ‘Xt’

clf :callable, always as a function, classifier estimator

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.

Xt: Ndarray ( M x N matrix where ``M=m-samples``, & ``N=n-features``)

Shorthand for “test set”; data that is observed at testing and prediction time, used as independent variables in learning. The notation is uppercase to denote that it is ordinarily a matrix.

prefix: str, optional

litteral string to prefix the samples/examples considered as tick labels in the abscissa. For instance:

index =[0, 2, 4, 7]
prefix ='b' --> index =['b0', 'b2', 'b4', 'b7']
predict: bool, default=False,

Expected to be ‘True’ when user want to predict the array ‘ypred’ and plot at the same time. Otherwise, can be set to ‘False’ and use the’ypred’ data already predicted. Note that, if ‘True’, an estimator/classifier must be provided as well as the test data ‘Xt’, otherwise an error will occur.

index: array_like, optional

list integer values or string expected to be the index of ‘Xt’ and ‘yt’ turned into pandas dataframe and series respectively. Note that one of them has already and index and new index is given, the latter must be consistent. This is usefull when data are provided as ndarray rathern than a dataframe.

fill_between: bool

Fill a line between the actual classes i.e the true labels.

labels: list of str or int, Optional

list of labels names to hold the name of each category.

return_pred: bool,

return predicted ‘ypred’ if ‘True’ else nothing.

baseplot_kws: dict,

All all the keywords arguments passed to the peroperty watex.property.BasePlot class.

(2)-> prepared our demo estimator and plot model predicted

>>> svc_clf = SVC(C=100, gamma=1e-2, kernel='rbf', random_state =42)
>>> base_plot_params ={
                    'lw' :3.,                  # line width
                    'lc':(.9, 0, .8),
                    'ms':7.,
                    'yp_marker' :'o',
                    'fig_size':(12, 8),
                    'font_size':15.,
                    'xlabel': 'Test examples',
                    'ylabel':'Flow categories' ,
                    'marker':'o',
                    'markeredgecolor':'k',
                    'markerfacecolor':'b',
                    'markeredgewidth':3,
                    'yp_markerfacecolor' :'k',
                    'yp_markeredgecolor':'r',
                    'alpha' :1.,
                    'yp_markeredgewidth':2.,
                    'show_grid' :True,
                    'galpha' :0.2,
                    'glw':.5,
                    'rotate_xlabel' :90.,
                    'fs' :3.,
                    's' :20 ,
                    'rotate_xlabel':90
               }
>>> plotModel(yt= ytest ,
               Xt=Xtest ,
               predict =True , # predict the result (estimator fit)
               clf=svc_clf ,
               fill_between= False,
               prefix ='b',
               labels=['FR0', 'FR1', 'FR2', 'FR3'], # replace 'y' labels.
               **base_plot_params
               )
>>> # plot show where the model failed to predict the target 'yt'