Importanza delle feature e SHAP
Su quali elementi il modello ha fatto maggiore affidamento.
Importanza delle feature e SHAP è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 1 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Data Science Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Data Science Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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. 🎯
Domande Frequenti
La lezione «Importanza delle feature e SHAP» è gratuita?
Sì — il testo completo di «Importanza delle feature e SHAP» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Data Science Academy, passa a CoddyKit PRO. Il corso Data Science Academy include 4 lezioni in totale.
Cosa imparerò in «Importanza delle feature e SHAP»?
Su quali elementi il modello ha fatto maggiore affidamento. Eserciti Data Science Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Data Science Academy?
Non è richiesta alcuna esperienza precedente. Data Science Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 1 di 4.
Quanto tempo richiede la lezione «Importanza delle feature e SHAP»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Data Science Academy?
Sì. Ogni lezione Data Science Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Importanza delle feature e SHAP
- Intuizione della dipendenza parziale
- Grafici che convincono gli stakeholder
- Dal notebook alla dashboard