random forest classifier feature importance code example

Example 1: random forrest plotting feature importance function

def plot_feature_importances(model):
    n_features = data_train.shape[1]
    plt.figure(figsize=(20,20))
    plt.barh(range(n_features), model.feature_importances_, align='center') 
    plt.yticks(np.arange(n_features), data_train.columns.values) 
    plt.xlabel('Feature importance')
    plt.ylabel('Feature')

Example 2: sklearn random forest feature importance

import pandas as pd
forest_importances = pd.Series(importances, index=feature_names)

fig, ax = plt.subplots()
forest_importances.plot.bar(yerr=std, ax=ax)
ax.set_title("Feature importances using MDI")
ax.set_ylabel("Mean decrease in impurity")
fig.tight_layout()

Example 3: sklearn random forest feature importance

RandomForestClassifier(random_state=0)

Example 4: sklearn random forest feature importance

print(__doc__)
import matplotlib.pyplot as plt

Tags:

Misc Example