Follow these four steps to initialize an explainer, compile your data, and view results.
1. Declare the SmartExplainer object
Initialize the explainer with your model. You can optionally provide a features_dict for labels, a preprocessing object (which should have an inverse_transform method), and a postprocessing function.
2. Compile the dataset
Use the .compile() method to link your data to the explainer. Mandatory parameter is x (the dataset).
3. Display output
Launch the interactive web application using .run_app().
4. Generate a Shapash Report
Create a standalone HTML report containing project metrics and data splits using .generate_report().
from shapash import SmartExplainer
# Step 1: Declare SmartExplainer Object
xpl = SmartExplainer(
features_dict=house_dict, # Optional
model=regressor, # Mandatory
preprocessing=encoder, # Optional
postprocessing=postprocess # Optional
)
# Step 2: Compile Dataset
xpl.compile(
x=Xtest,
y_pred=y_pred, # Optional
y_target=yTest, # Optional
additional_data=X_additional, # Optional
additional_features_dict=features_dict_additional, # Optional
)
# Step 3: Display output (Web App)
app = xpl.run_app()
# Step 4: Generate the Shapash Report
xpl.generate_report(
output_file='path/to/output/report.html',
project_info_file='path/to/project_info.yml',
x_train=Xtrain,
y_train=ytrain,
y_test=ytest,
title_story="House prices report",
title_description="""This document is a data science report of the kaggle house prices tutorial project. It was generated using the Shapash library.
""",
metrics=[{'name': 'MSE', 'path': 'sklearn.metrics.mean_squared_error'}]
)