def plot_importance(names, model, savefig=True):
featureNames = numpy.array(names)
featureImportance = model.feature_importances_
featureImportance = featureImportance / featureImportance.max()
sorted_idx = numpy.argsort(featureImportance)
barPos = numpy.arange(sorted_idx.shape[0]) + .5
plot.barh(barPos, featureImportance[sorted_idx], align='center')
plot.yticks(barPos, featureNames[sorted_idx])
plot.xlabel('Variable Importance')
plot.subplots_adjust(left=0.2, right=0.9, top=0.9, bottom=0.1)
if savefig:
dt_ = datetime.datetime.now().strftime('%d%b%y_%H%M')
plt.savefig("../graphs/featureImportance_" + dt_ + ".png")
plot.show()
# Plot prediction save the graph with a timestamp
评论列表
文章目录