Feature Importance in LightGBM

LightGBM provides built-in feature importance and supports SHAP values for interpretation. Understanding what drives your model is crucial for trust and improvement.

Built-in Importance

import lightgbm as lgb
import matplotlib.pyplot as plt

# Train model
model = lgb.train(params, train_data, num_boost_round=500)

# Get importance
df_importance = pd.DataFrame({
    'feature': model.feature_name(),
    'importance': model.feature_importance(importance_type='gain')
}).sort_values('importance', ascending=False)

# Plot top 15
plt.figure(figsize=(10, 8))
plt.barh(range(15), df_importance['importance'].head(15))
plt.yticks(range(15), df_importance['feature'].head(15))
plt.xlabel('Feature Importance (Gain)')
plt.title('Top 15 Features')
plt.tight_layout()
plt.show()

Importance Types

  • split: Number of times feature is used for splitting
  • gain: Total gain from splits using this feature
  • cover: Number of samples affected by splits
# Compare importance types
importance_split = model.feature_importance(importance_type='split')
importance_gain = model.feature_importance(importance_type='gain')
importance_cover = model.feature_importance(importance_type='cover')

SHAP Values

import shap

# Create SHAP explainer
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_test)

# Summary plot
shap.summary_plot(shap_values, X_test, plot_type='bar')

# Detailed beeswarm plot
shap.summary_plot(shap_values, X_test)

# Dependence plot
shap.dependence_plot('pcr', shap_values, X_test)

Interpreting Results

Common important features for Nifty trading:

  1. PCR (Put-Call Ratio): Market sentiment indicator
  2. IV Rank: Volatility regime
  3. Momentum: Trend strength
  4. Volume Ratio: Market participation
  5. RSI: Overbought/oversold

Monitoring Importance Drift

# Track importance over time
importance_history = []

for period in range(n_periods):
    # Train model for period
    model = train_model(X_periods[period], y_periods[period])
    
    # Record importance
    importance = pd.Series(
        model.feature_importance(importance_type='gain'),
        index=model.feature_name()
    )
    importance_history.append(importance)

# Plot importance drift
importance_df = pd.DataFrame(importance_history)
importance_df.plot(figsize=(12, 6))
plt.title('Feature Importance Over Time')
plt.ylabel('Importance')
plt.show()

Practical Tips

  • Use gain importance for most interpretations
  • Validate with SHAP for individual predictions
  • Monitor drift — changing importance indicates regime change
  • Remove unimportant features to reduce overfitting

Gain Versus Split: Reading the Two Built-In Numbers

LightGBM reports two importance statistics and they tell different stories:

  • Split count: how often a feature was chosen for splitting; favours high-cardinality, noisy variables that keep winning coin-flip splits.
  • Gain: the total improvement in the objective across all splits using a feature; this is the economically meaningful one for trading systems.

Check both and distrust the gap: a feature that tops splits but ranks low on gain is being over-selected by noise; a feature that ranks high on gain but rarely splits is the concentrated edge worth investigating deeper.

Collinearity: The Blame Problem

Correlated features split importance between them, hiding the true driver. Two features measuring the same momentum concept at different lags will each show half the importance either would alone:

  • Group correlated features into families (momentum, volatility, volume, flow) and rank by family gain before ranking individuals.
  • When one family dominates, remove its redundant members and retrain; importance typically re-centres on the few genuine drivers.
  • Never prune features by SHAP importance alone; collinear twins survive pruning together and the model's behaviour changes on unseen data.

Grouping Importance by Feature Family

Ranking 200 raw features produces a noisy table; ranking by family produces a strategy:

  • Sum importance across a family, then ask: is volatility worth 38% of this model's predictive power?
  • Feed the family ranking into feature-selection choices: cap the model at 2-3 top families and rebuild, isolating the real alpha contributors.
  • Reassess the family weights after every regime change; a model where momentum collapses to 5% importance after a crash is telling you the market rewired.

Importance Drift Over Time

The healthiest monitoring run plots importance over rolling windows, because a strategy that was built on one set of drivers goes stale the week the drivers change:

  • Track top-10 importance membership per month; when two or more new members enter, schedule a retrain.
  • Alert when a previously dominant family's importance halves: that is either genuine regime change or a data bug, and both require scrutiny.
  • Keep importance drift as part of your model review pack, verified against market events like a Budget day or an expiry Jan 26 holiday shift.

Reporting Importance to a Trader, Not a Data Scientist

The final skill is translation. A trader cares whether the model agrees with market logic:

  • Present the top drivers as narratives: "the model spent 40% of its decisions on how far OTM your short strikes were, and 25% on how fat IV is right now."
  • Show one counterfactual: change the top feature's state by one standard deviation and display the change in expected win rate.
  • Get agreement or disagreement stated before deployment; a model whose top features contradict the trader's own edge theory almost never survives contact with live capital.

Feature importance is the model's testimony to the market. Read gain over splits, rank by family before individual, watch the drift, and translate it into the trader's language; that discipline is what separates a model you trust from one you merely run.