watex.utils.plot_rf_feature_importances#

watex.utils.plot_rf_feature_importances(clf, X=None, y=None, fig_size=(8, 4), savefig=None, n_estimators=500, verbose=0, sns_style=None, **kws)[source]#

Plot features importance with RandomForest.

Parameters
  • clf (estimator object) – The base estimator from which the transformer is built. This can be both a fitted (if prefit is set to True) or a non-fitted estimator. The estimator should have a feature_importances_ or coef_ attribute after fitting. Otherwise, the importance_getter parameter should be used.

  • 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.

  • kws (dict,) – Additional keyyword arguments passed to sklearn.ensemble.RandomForestClassifier

Examples

>>> from watex.datasets import fetch_data
>>> from watex.exlib.sklearn import RandomForestClassifier
>>> from watex.utils.plotutils import plot_rf_feature_importances
>>> X, y = fetch_data ('bagoue analysed' )
>>> plot_rf_feature_importances (
    RandomForestClassifier(), X=X, y=y , sns_style=True)