1. Learn
  2. /
  3. Courses
  4. /
  5. Machine Learning with Tree-Based Models in Python

Connected

Exercise

Visualizing features importances

In this exercise, you'll determine which features were the most predictive according to the random forests regressor rf that you trained in a previous exercise.

For this purpose, you'll draw a horizontal barplot of the feature importance as assessed by rf. Fortunately, this can be done easily thanks to plotting capabilities of pandas.

We have created a pandas.Series object called importances containing the feature names as index and their importances as values. In addition, matplotlib.pyplot is available as plt and pandas as pd.

Instructions

100 XP
  • Call the .sort_values() method on importances and assign the result to importances_sorted.

  • Call the .plot() method on importances_sorted and set the arguments:

    • kind to 'barh'
    • color to 'lightgreen'