<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Title
Step1:  Load Iris Flower Dataset
Step2:  Train A Decision Tree Model
Step3:  View Feature Importance
Step4:  Visualize Feature Importance
<ASSISTANT_TASK:>
Python Code:
# Load libraries
from sklearn.ensemble import RandomForestClassifier
from sklearn import datasets
import numpy as np
import matplotlib.pyplot as plt
Explanation: Title: Feature Importance
Slug: feature_importance
Summary: How to identify important features in random forest in scikit-learn.
Date: 2017-09-21 12:00
Category: Machine Learning
Tags: Trees And Forests
Authors: Chris Albon  
<a alt="Feature Importance" href="https://machinelearningflashcards.com">
    <img src="feature_importance/Feature_Importance_print.png" class="flashcard center-block">
</a>
Preliminaries
End of explanation
# Load data
iris = datasets.load_iris()
X = iris.data
y = iris.target
Explanation: Load Iris Flower Dataset
End of explanation
# Create decision tree classifer object
clf = RandomForestClassifier(random_state=0, n_jobs=-1)
# Train model
model = clf.fit(X, y)
Explanation: Train A Decision Tree Model
End of explanation
# Calculate feature importances
importances = model.feature_importances_
Explanation: View Feature Importance
End of explanation
# Sort feature importances in descending order
indices = np.argsort(importances)[::-1]
# Rearrange feature names so they match the sorted feature importances
names = [iris.feature_names[i] for i in indices]
# Create plot
plt.figure()
# Create plot title
plt.title("Feature Importance")
# Add bars
plt.bar(range(X.shape[1]), importances[indices])
# Add feature names as x-axis labels
plt.xticks(range(X.shape[1]), names, rotation=90)
# Show plot
plt.show()
Explanation: Visualize Feature Importance
End of explanation
<END_TASK>