In this example, we'll be plotting the feature importances in a RandomForestClassifier
for the Iris dataset. In order for this to work, we need to first create an instance of our classifier then fit it to our data.
In [1]:
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris as load_data
import matplotlib.pyplot as plt
# Import scikit-plot
import scikitplot as skplt
%pylab inline
pylab.rcParams['figure.figsize'] = (12, 12)
In [2]:
# Load data
X, y = load_data(return_X_y=True)
# Create classifier instance and fit
classifier = RandomForestClassifier(random_state=1)
classifier.fit(X,y)
Out[2]:
In [3]:
skplt.estimators.plot_feature_importances(classifier, feature_names=['petal length', 'petal width',
'sepal length', 'sepal width'])
plt.show()