NelworksNelworks

ML & AI / Season 2 / EP01

Feature Importance (MDI, Permutation, SHAP) & Causal Misinterpretation

Shez

And finally, the AI has spoken! We now know exactly what drives our sales!

Shez

Look! 'Transaction_ID' is the most important feature!

Shez

We need to optimize our Transaction IDs! If we make them bigger, we'll make more money!

Kurumi

Shez. The 'Transaction_ID' is a unique number for every row.

Shez

Yeah! And the Random Forest loves it! 'feature_importances_' gave it a score of 0.4!

Kurumi

Your model is as retarded as you.

Kurumi

This is **Gini Importance** (Mean Decrease in Impurity).

Kurumi

Trees are lazy. They want to separate the data into clean buckets as fast as possible. What is the easiest way to identify a specific row?

Kurumi

A 'Red Shirt' (Low Cardinality) is a weak splitter. An 'ID Card' (High Cardinality) is a perfect splitter.

Kurumi

The tree grabs the ID card every time because it guarantees a 'Pure' leaf node.

Kurumi

It mistakes 'Memorization' for 'Importance.'

Shez

So... 'Transaction_ID' is just... noise?

Kurumi

It's high-cardinality garbage. The model overfitted to it.

Shez

Okay, okay! Ignored. But look at the second one! 'Ice Cream Sales.'

Shez

It predicts 'Shark Attacks' perfectly!

Shez

We need to ban ice cream to stop the sharks!

Kurumi

(Facepalming) Noooo. Not the correlation fallacy again.

Kurumi

The Sun (Summer) causes Ice Cream Sales.

Kurumi

The Sun (Summer) causes Shark Attacks (people swimming).

Kurumi

Ice Cream and Sharks are **Correlated**, but not **Causal**.

Kurumi

Your Random Forest doesn't know what the Sun is. It only sees the Ice Cream data.

Kurumi

So it says: 'Ice Cream is an important predictor.'

Shez

But... if the model works, does it matter?

Kurumi

It matters if you try to *act* on it. If you ban ice cream, the sharks will still eat you.

Shez

So 'feature_importances_' is useless?

Kurumi

It's useful for **Debugging**. It tells you what the model is looking at.

Kurumi

It does *not* tell you how the universe works.

Shez

Is there a better way? A way to prove the feature actually does work?

Kurumi

We stop asking the tree what it *thinks*. We test what it *needs*.

Shez

Permutation... shuffling?

Kurumi

Imagine the model is a Jenga tower. We want to know which block is holding it up.

Kurumi

If I scramble (shuffle) a noise feature, the model's accuracy doesn't change.

Kurumi

Importance = 0.

Kurumi

If I scramble 'Price,' the model fails.

Kurumi

Therefore, 'Price' is **Load-Bearing**.

Shez

That makes sense! We break the data and see if the model cries!

Shez

'from sklearn.inspection import permutation_importance'.

Shez

I'm going to shuffle everything!

Kurumi

Wait. There is a catch.

Shez

...there's always a catch...

Kurumi

What happens if you shuffle the 'Pregnant' column randomly?

Shez

...I'm not woke enough to think this is possible...

Kurumi

That is **Out-of-Distribution (OOD)** data.

Kurumi

When you permute correlated features, you create impossible monsters.

Kurumi

The model has never seen a pregnant man. It might output a crazy prediction, causing a huge error spike.

Kurumi

You will think 'Pregnant' is super important, but really, you just confused the model with nonsense.

Shez

Standard importance is biased. Permutation creates monsters. Is nothing real?

Kurumi

Try **SHAP** (Shapley Additive Explanations).

Kurumi

Imagine every feature is a player on a team, trying to pull the prediction away from the baseline.

Kurumi

We want to know: how much does Player A *actually* pull the rope?

Kurumi

To be fair, we try every lineup: Player A alone, with Player B, with Player C and D, every possible combo.

Kurumi

SHAP calculates the *marginal contribution* of each feature, averaged over all these coalitions.

Kurumi

If Player A and Player B always pull together, SHAP splits the credit fairly between them.

Shez

It's colorful. Lots of red and blue dots!

Kurumi

It even shows *direction*: High Price (red) might push probability left, Low Price (blue) pushes right.

Shez

So SHAP tells me the Truth?

Kurumi

No.

Shez

What?!

Kurumi

SHAP explains the **Model**. It faithfully describes the math inside the black box.

Kurumi

If your model uses 'Ice Cream' to predict 'Sharks,' SHAP will faithfully tell you: 'Ice Cream increases Shark Risk.'

Kurumi

It explains the *Model's Logic*. It does not validate the *Model's Logic*.

Kurumi

Feature Importance is a mirror. It reflects the biases, the shortcuts, and the correlations your model learned.

Shez

So I shouldn't call it 'Drivers of Revenue.'

Shez

I should just call it... 'Stuff the Model Likes.'

Kurumi

Yup. 'These are the levers the AI is pulling. We need to verify if they are actually attached to anything real.'

Kurumi

And delete the 'Transaction_ID' column before the shareholder meeting. You're gonna crash our stock when our shareholders sees it.

Shez

Deleting!