ML.INSPECT.FEATURE_IMPORTANCES¶
Returns the feature importances of a fitted tree-ensemble model.
Syntax¶
Arguments¶
| Name | Type | Default | Description |
|---|---|---|---|
| model | object | Fitted tree-ensemble model with a feature_importances_ attribute (e.g. created by ML.CLASSIFICATION.RANDOM_FOREST_CLF and trained with ML.FIT). |
Returns¶
A DataFrame with columns [feature, importance], one row per training feature.
When to use¶
Use ML.INSPECT.FEATURE_IMPORTANCES to read the per-feature feature_importances_
score from a fitted tree-ensemble model (Random Forest, Extra Trees, gradient
boosting, etc.). Higher values indicate features the model relied on more
heavily when choosing where to split the data.
A common use is to rank predictors after a one-shot fit: train the model on the full feature set, pull the importances back into Excel, and chart them as a bar chart to see which inputs carry the predictive signal.
Examples¶
Train a Random Forest on the data in A2:K100 (predictors) and L2:L100
(target), then read the importances:
=ML.CLASSIFICATION.RANDOM_FOREST_CLF(100, "gini", , 2, 1, 1, TRUE, 0)
=ML.FIT(N1, A2:K100, L2:L100)
=ML.INSPECT.FEATURE_IMPORTANCES(N2)
Pair the result with a bar chart that uses the feature column as categories
and the importance column as values to get a ranked bar chart.
Remarks¶
- The model passed in must already be fitted and must expose a
feature_importances_attribute. Linear models (LinearRegression,LogisticRegression,Ridge,Lasso) exposecoef_instead, notfeature_importances_, so they will be rejected. For coefficients, useML.INSPECT.COEFFICIENTSonce available. - When the model was fitted on a DataFrame, the
featurecolumn uses the original column names. When fitted on an unnamed array, it falls back tofeature_0,feature_1, … in input order. - Tree-ensemble importances are impurity-based (mean decrease in impurity). They favour high-cardinality features and can be misleading when features are strongly correlated. For comparing across pipelines, consider permutation importance or SHAP — neither is exposed in this add-in yet.
- Importances sum to ~1.0 for a standard Random Forest. Use the relative ranking, not the absolute value, when comparing across models.