Despite the great interest, I do not know the answer to the main question. Meanwhile, I can help with the second.
After setting the model, you can access the value of the function through the attribute model.feature_importances_
I use the following function to normalize the importance and show it in a more beautiful way.
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
def showFeatureImportance(model):
feature_importance = model.feature_importances_
feature_importance = 100.0 * (feature_importance / Feature_importance.max())
sorted_idx = np.argsort(feature_importance)
pos = np.arange(sorted_idx.shape[0]) + .5
plt.figure(figsize=(12, 12))
plt.barh(pos, feature_importance[sorted_idx], align='center', color='#7A68A6')
plt.yticks(pos, np.asanyarray(X_cols)[sorted_idx])
plt.xlabel('Relative Importance')
plt.title('Feature Importance')
plt.show()
source
share