watex.utils.plot_sbs_feature_selection#
- watex.utils.plot_sbs_feature_selection(sbs_estimator, /, X=None, y=None, fig_size=(8, 5), sns_style=False, savefig=None, verbose=0, **sbs_kws)[source]#
plot Sequential Backward Selection (SBS) for feature selection.
SBS collects the scores of the best feature subset at each stage.
- Parameters:
sbs_estimator (
SequentialBackwardSelectionestimator object) – The Sequential Backward Selection estimator can either be fitted or not. If not fitted. Please provide the training X and y, otherwise an error will occurs.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.
n_estimators (int, default=500) – The number of trees in the forest.
fig_size (tuple (width, height), default =(8, 6)) – the matplotlib figure size given as a tuple of width and height
savefig (str, default =None ,) – the path to save the figures. Argument is passed to matplotlib.Figure class.
sns_style (str, optional,) – the seaborn style.
verbose (int, default=0) – print the feature labels with the rate of their importances.
sbs_kws (dict,) – Additional keyyword arguments passed to
SequentialBackwardSelection
Examples
(1)-> Plot fitted SBS in action >>> from watex.exlib.sklearn import KNeighborsClassifier , train_test_split >>> from watex.datasets import fetch_data >>> from watex.base import SequentialBackwardSelection >>> from watex.utils.plotutils import plot_sbs_feature_selection >>> X, y = fetch_data(‘bagoue analysed’) # data already standardized >>> Xtrain, Xt, ytrain, yt = train_test_split(X, y) >>> knn = KNeighborsClassifier(n_neighbors=5) >>> sbs= SequentialBackwardSelection (knn) >>> sbs.fit(Xtrain, ytrain ) >>> plot_sbs_feature_selection(sbs, sns_style= True)
(2)-> Plot estimator with no prefit SBS. >>> plot_sbs_feature_selection(knn, Xtrain, ytrain) # yield the same result