watex.utils.plot_learning_curves#
- watex.utils.plot_learning_curves(models, X, y, *, cv=None, train_sizes=None, baseline_score=0.4, scoring=None, convergence_line=True, fig_size=(20, 6), sns_style=None, savefig=None, set_legend=True, subplot_kws=None, **kws)[source]#
Horizontally visualization of multiple models learning curves.
Determines cross-validated training and test scores for different training set sizes.
- Parameters:
models (list or estimators) – An estimator instance or not that implements fit and predict methods which will be cloned for each validation.
X (array-like of shape (n_samples, n_features)) – Training vector, where n_samples is the number of samples and n_features is the number of features.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Target relative to X for classification or regression; None for unsupervised learning.
cv (int, cross-validation generator or an iterable, default=None) –
- Determines the cross-validation splitting strategy.
Possible inputs for cv are:
None, to use the default 5-fold cross validation,
int, to specify the number of folds in a (Stratified)KFold,
CV splitter,
An iterable yielding (train, test) splits as arrays of indices.
For int/None inputs, if the estimator is a classifier and
yis either binary or multiclass,StratifiedKFoldis used. In all other cases,KFoldis used. These splitters are instantiated with shuffle=False so the splits will be the same across calls.Refer User Guide for the various cross-validation strategies that can be used here.
cvdefault value if None changed from 3-fold to 4-fold.- train_sizesarray-like of shape (n_ticks,), default=np.linspace(0.1, 1, 50)
Relative or absolute numbers of training examples that will be used to generate the learning curve. If the dtype is float, it is regarded as a fraction of the maximum size of the training set (that is determined by the selected validation method), i.e. it has to be within (0, 1]. Otherwise it is interpreted as absolute sizes of the training sets. Note that for classification the number of samples usually have to be big enough to contain at least one sample from each class.
baseline_score (floatm default=.4) – base score to start counting in score y-axis (score)
scoring (str or callable, default=None) – A str (see model evaluation documentation) or a scorer callable object / function with signature
scorer(estimator, X, y).convergence_line (bool, default=True) – display the convergence line or not that indicate the level of bias between the training and validation curve.
fig_size (tuple (width, height), default =(14, 6)) – the matplotlib figure size given as a tuple of width and height
sns_style (str, optional,) – the seaborn style .
set_legend (bool, default=True) – display legend in each figure. Note the default location of the legend is ‘best’ from
legend()subplot_kws (dict, default is dict(left=0.0625, right = 0.95, wspace = 0.1)) – the subplot keywords arguments passed to
matplotlib.subplots_adjust()kws (dict,) – keyword arguments passed to
sklearn.model_selection.learning_curve()
Examples
-> plot via a metaestimator already cross-validated.
>>> from watex.models.premodels import p >>> from watex.datasets import fetch_data >>> from watex.utils.plotutils import plot_learning_curves >>> X, y = fetch_data ('bagoue prepared') # yields a sparse matrix >>> # let collect 04 estimators already cross-validated from SVMs >>> models = [ p.SVM.linear , p.SVM.rbf , p.SVM.sigmoid , p.SVM.poly ] >>> plot_learning_curves (models, X, y, cv=4, sns_style = 'darkgrid')
-> plot with multiples models not crossvalidated yet.
>>> from watex.exlib.sklearn import (LogisticRegression, RandomForestClassifier, SVC , KNeighborsClassifier ) >>> models =[LogisticRegression(), RandomForestClassifier(), SVC() , KNeighborsClassifier() ] >>> plot_learning_curves (models, X, y, cv=4, sns_style = 'darkgrid')