<jupyter_start><jupyter_text>Interactions plotMost explainability plots only allow the user to analyze one variable at a time. **Interactions plots are an interesting way to visualize a couple of variables and their corresponding contribution to the model output.**Shapash integrates two methods that allow to display such interactions for several individuals : `interactions_plot` and `top_interactions_plot`.This tutorial presents how to use both methods to get more insights about your model and how two variables interact with it.Content :- Loading dataset and fitting a model- Declare and compile Shapash smart explainer- Plot top interaction values- Plot a chosen couple of variablesWe used Kaggle's [Titanic](https://www.kaggle.com/c/titanic/data) dataset<jupyter_code>import pandas as pd
from category_encoders import OrdinalEncoder
from xgboost import XGBClassifier
from sklearn.model_selection import train_test_split<jupyter_output><empty_output><jupyter_text>Building Supervized Model Load Titanic data<jupyter_code>from shapash.data.data_loader import data_loading
titanic_df, titanic_dict = data_loading('titanic')
del titanic_df['Name']
y_df=titanic_df['Survived']
X_df=titanic_df[titanic_df.columns.difference(['Survived'])]
titanic_df.head()
from category_encoders import OrdinalEncoder

categorical_features = [col for col in X_df.columns if X_df[col].dtype == 'object']

encoder = OrdinalEncoder(
    cols=categorical_features,
    handle_unknown='ignore',
    return_df=True).fit(X_df)

X_df=encoder.transform(X_df)<jupyter_output><empty_output><jupyter_text>Train / Test Split + model fitting<jupyter_code>Xtrain, Xtest, ytrain, ytest = train_test_split(X_df, y_df, train_size=0.75, random_state=7)
clf = XGBClassifier(n_estimators=200,min_child_weight=2).fit(Xtrain,ytrain)<jupyter_output><empty_output><jupyter_text>Declare and Compile SmartExplainer<jupyter_code>from shapash.explainer.smart_explainer import SmartExplainer
response_dict = {0: 'Death', 1:' Survival'}
xpl = SmartExplainer(features_dict=titanic_dict, # Optional parameters
                     label_dict=response_dict) # Optional parameters, dicts specify labels 
xpl.compile(
    x=Xtest,
    model=clf,
    preprocessing=encoder, # Optional: compile step can use inverse_transform method
)<jupyter_output>Backend: Shap TreeExplainer<jupyter_text>Plot top interactions Now we may want to analyze our model and in particular how some variables combinations influence the output.**Shapash allows to quickly inspect your model by showing the variables for which there is the highest chance to get interesting interactions.**To do so you can use the following method (use the button to see the different variables interactions) :<jupyter_code>xpl.plot.top_interactions_plot(nb_top_interactions=5)<jupyter_output><empty_output><jupyter_text>Plot interactions between two selected variables If you want to display a particular couple of interactions just use the following method with the chosen features (here 'Sex' and 'Pclass'):<jupyter_code>xpl.plot.interactions_plot('Sex', 'Pclass')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07280927835051547, 'fraction_numerical': 0.0035438144329896907, 'mean_word_length': 7.0859375, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '142359', 'license': 'Apache-2.0', 'n_tokens_mistral': 939, 'n_tokens_neox': 904, 'n_words': 283, 'path': 'tutorial/plot/tuto-plot05-interactions-plot.ipynb', 'repo_name': 'amnaabbassi/shapash', 'size': '3104'}