1. Learn
  2. /
  3. Courses
  4. /
  5. Extreme Gradient Boosting with XGBoost

Connected

Exercise

Visualizing feature importances: What features are most important in my dataset

Another way to visualize your XGBoost models is to examine the importance of each feature column in the original dataset within the model.

One simple way of doing this involves counting the number of times each feature is split on across all boosting rounds (trees) in the model, and then visualizing the result as a bar graph, with the features ordered according to how many times they appear. XGBoost has a plot_importance() function that allows you to do exactly this, and you'll get a chance to use it in this exercise!

Instructions

100 XP
  • Create your DMatrix from X and y as before.
  • Create a parameter dictionary with appropriate "objective" ("reg:squarederror") and a "max_depth" of 4.
  • Train the model with 10 boosting rounds, exactly as you did in the previous exercise.
  • Use xgb.plot_importance() and pass in the trained model to generate the graph of feature importances.