0Pricing
Data Science Academy · Lesson

Feature Importance and SHAP

What the model relied on most.

Feature Importance and SHAP is a free Data Science Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Which Features Mattered?

After a model trains, you want to know which inputs drove its predictions. That ranking is called feature importance. 🔍

Built-In Tree Importance

Tree models expose a quick feature_importances_ array. Higher values mean the feature was used more often to split the data.

importances = model.feature_importances_

Pair It With Names

The importances array is just numbers, so zip it with your column names to read which feature each score belongs to.

import pandas as pd
fi = pd.Series(model.feature_importances_, index=X.columns)

Sort to See Top Drivers

Sorting the importance Series surfaces the few features that carry most of the signal in your model.

fi.sort_values(ascending=False).head()

The Catch With Trees

Built-in tree scores can favor high-cardinality columns. They tell you usage, not always real impact on predictions.

Permutation Importance

A fairer, model-agnostic method is permutation importance: shuffle one column and measure how much the score drops.

from sklearn.inspection import permutation_importance
r = permutation_importance(model, X_test, y_test)

Enter SHAP

For per-prediction detail you use SHAP values, which fairly split each prediction among the features that produced it.

SHAP Is Game Theory

SHAP borrows from game theory: each feature is a player, and its value is the credit it earns toward one specific prediction.

Compute SHAP Values

You build an explainer for your fitted model, then ask it for SHAP values on the rows you care about.

import shap
explainer = shap.Explainer(model)
values = explainer(X_test)

Global From Local

Average the absolute SHAP values across all rows and you get a trustworthy global importance ranking, built from local explanations.

shap.plots.bar(values)

Explain One Prediction

SHAP also shows why a single row scored as it did, listing which features pushed the prediction up and which pulled it down.

shap.plots.waterfall(values[0])

Quick Check

Which method gives a fair, model-agnostic importance score?

Recap

You ranked features with tree, permutation, and SHAP methods, moving from quick scores to fair, per-prediction credit. Next, how one feature moves output. 🎯

Frequently asked questions

Is the “Feature Importance and SHAP” lesson free?

Yes — the full text of “Feature Importance and SHAP” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “Feature Importance and SHAP”?

What the model relied on most. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Feature Importance and SHAP” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Feature Importance and SHAP
  2. Partial Dependence Intuition
  3. Charts That Persuade Stakeholders
  4. From Notebook to Dashboard
← Back to Data Science Academy