liveBook · Manning

Importance score

As explained in Statistics Every Programmer Needs

Feature importance is a measure of how strongly each input feature contributes to a model's predictions, often based on its effect on split quality.

An importance score estimates how strongly an input feature contributes to a model’s predictions. In a random forest, it reflects the feature’s contribution to impurity reduction across the trees: features producing consistently better splits receive higher scores. section 6.4.4 section 6.5

Interpret scores as relative contributions within the fitted model:

  • Higher values indicate features with greater influence on the model’s predictions; lower values indicate less influence. section 6.4.4
  • Aggregate scores across the forest rather than inspecting individual trees, making feature ranking practical for ensembles. section 6.4.4
  • Use rankings to improve transparency and guide data preprocessing or feature engineering. section 6.4.4

Fourth-down conversion model

A RandomForestClassifier ranks features by descending importance. In the displayed analysis, TO_GO and PLAY_TYPE account for approximately 80% of the model’s predictive power. A score of 0.6 therefore indicates substantially more relative influence than a score of 0.1. section 6.1 section 6.4.4

>>> importances = rf.feature_importances_  #1
>>> features = X.columns     #2
>>> indices = np.argsort(importances)[::-1]    #3




>>> sorted_features = features[indices]    #4
>>> sorted_importances = importances[indices]    #5
>>> plt.figure()   #6
>>> plt.bar(sorted_features, sorted_importances)    #7
>>> plt.xlabel('Feature')     #8
>>> plt.ylabel('Feature Importance')  #9
>>> plt.title('Feature Importance in \
>>>            RandomForestClassifier')  #10
>>> plt.tight_layout()   #11
>>> plt.show()     #12

Extract feature_importances_, sort features with NumPy, and visualize their relative scores as a Matplotlib bar chart. section 6.4.4

How Statistics Every Programmer Needs covers it

How deep it goes
Defines impurity-based scoring, explains relative values, and demonstrates forest-wide visualization without discussing alternative importance methods.
Examples
Uses fourth-down conversion prediction, TO_GO, PLAY_TYPE, importance scores, and a sorted bar chart.
What it assumes
Assumes a fitted decision tree or random forest and feature columns, while explaining the score interpretation from zero.
What you can do after
Apply it via RandomForestClassifier and Matplotlib to rank and visualize influential features.
How it connects
Connects feature importance to decision trees, random forests, impurity reduction, preprocessing, and feature engineering.

Also explained in

Compare how 6 books explain importance score →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.