[Python] SHAP waterfall plot has only three features while the data has 900

Discussão em 'Python' iniciado por Stack, Maio 25, 2025.

  1. Stack

    Stack Membro Participativo

    explainer = shap.Explainer(self.model)
    sv = np.array(explainer.shap_values(self.X_valid))
    ev = np.array(explainer.expected_value)
    idx = 0
    print(self._feature_cols) # 921 feature names
    print(self.X_valid.shape) # (57353, 921)
    shap.plots.waterfall(shap.Explanation(sv[1][idx], ev[idx], data=self.X_valid.iloc[idx],
    feature_names=self._feature_cols), max_display=20)


    Even after setting max_display to 20, I still only ever get the same three features, no idea why.

    The three features aren't even the top in self.model.feature_importances_, so I have no idea why these in particular are being displayed, but not the hundreds of other features.

    I tried both Explainer and TreeExplainer,

    For reference, my model is defined as:

    self.model = lgb.LGBMClassifier(
    device='gpu',
    boosting_type='gbdt',
    max_depth=6,
    n_estimators=500,
    learning_rate=0.05,
    objective='multiclass',
    num_class=len(self.fe.bins_labels),
    metric='multi_logloss',
    class_weight=class_weight_dict,
    random_state=Trainer.seed,
    min_child_samples=60,
    min_split_gain=0.1,
    verbose=-1
    )

    Continue reading...

Compartilhe esta Página