pip install shapash★Core library (Python 3.11–3.14).pip install shapash[report]Extra deps to enable generate_report.pip install shapash[xgboost,lightgbm,catboost]Optional model backends.from shapash import SmartExplainer★The one class you start from.
# any fitted, compatible modelRegression · binary · multiclass.regressor.fit(Xtrain, ytrain)Catboost · Xgboost · LightGBM · Sklearn · linear · SVM.y_pred = regressor.predict(Xtest)Optional — Shapash defaults tomodel.predict.encoder = OrdinalEncoder(...).fit(X)category-encoders / ColumnTransformer for clean labels.
xpl = SmartExplainer(model=regressor)★model is the one required arg.…, features_dict=house_dictoptMap raw names → human labels.…, preprocessing=encoderoptLets plots inverse-transform to raw values.…, backend='shap'opt'shap'(default) or'lime'.…, label_dict={0:'Death',1:'Survival'}optReadable class names (classification).
xpl.compile(x=Xtest)★x is the only required arg — computes contributions.…, y_pred=y_predoptYour own predictions to explain.…, y_target=ytestoptEnables True-vs-Predicted plots.…, additional_data=X_extraoptExtra columns for filtering in the web app.
xpl.plot.features_importance()★Sum of |contributions| per feature — start here.…features_importance(selection=subset)Compare a subset vs the whole population.xpl.plot.contribution_plot('Age')★How one feature's value drives the output (auto violin/scatter).xpl.plot.top_interactions_plot()Strongest pairwise feature interactions.
xpl.plot.local_plot(index=42)★Why row 42 got its prediction — bars ± per feature.…local_plot(row_num=0)Select by position instead of index label.…local_plot(query="Age > 60")Select the single row matching a condition.xpl.plot.compare_plot(row_num=[0,1,2])★Side-by-side: why these individuals differ.xpl.plot.local_neighbors_plot(index=42)Are near-identical rows explained the same way?
xpl.filter(max_contrib=8)★Cap how many features the summary shows.…filter(threshold=0.01)Hide contributions below a magnitude.…filter(positive=True)Keep only positive (or negative) drivers.xpl.to_pandas(max_contrib=5)★Export the local summary as a DataFrame.xpl.add(y_pred=new_pred)Attach / update preds or labels after compile.
xpl.plot.stability_plot()★Stability — similar rows get similar contributions.…stability_plot(distribution='boxplot')Show spread of variability per feature.xpl.plot.compacity_plot()Compacity — how few features explain ~90% of output.xpl.plot.consistency_plot()Consistency — do shap & lime agree?
app = xpl.run_app()★Launch the interactive explorer (global ⇄ local).xpl.run_app(title_story="My model")Title shown in the app header.xpl.run_app(port=8050)Pin host / port if needed.app.kill()Stop the running app thread.
xpl.generate_report(★One self-contained HTML file for auditors / DPO / risk.output_file='report.html',Where to write it.project_info_file='info.yml',Project title, purpose, authors, data prep.x_train=Xtrain, y_train=ytrain,Splits used to enrich the document.metrics=[{'name':'MSE','path':...}])Metrics to freeze into the snapshot.
predictor = xpl.to_smartpredictor()★Light object for API / batch — with consistency checks.predictor.add_input(x=new_df)Feed raw (un-preprocessed) rows to score.predictor.detail_contributions()Predictions + their local contributions.predictor.summarize()Wordy, human-readable local explanation.predictor.save('pred.pkl')Pickle it for the serving layer.
xpl.save('xpl.pkl')Persist the compiled explainer.xpl2 = SmartExplainer.load('xpl.pkl')Reload without recomputing contributions.from shapash.utils.load_smartpredictor import load_smartpredictorLoader for a saved SmartPredictor pickle.
index=1023by the DataFrame's index labelrow_num=0by 0-based positionquery="Pclass==1 & Age>60"by a condition matching one rowselection=[3,7,12]a subset for global plotslabel='Survival'which class to explain (classification)max_contrib=10how many features to show