<jupyter_start><jupyter_text>`models.explainers` binary classification example (adult dataset)----- Load packages<jupyter_code>from transparentai.models import explainers
from transparentai.datasets import load_adult

from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split<jupyter_output><empty_output><jupyter_text>Load & prepare data<jupyter_code>data = load_adult()
X, Y = data.drop(columns='income'), data['income']
X = X.select_dtypes('number')
Y = Y.replace({'>50K':1, '<=50K':0})<jupyter_output><empty_output><jupyter_text>Split train test<jupyter_code>X_train, X_valid, Y_train, Y_valid = train_test_split(X, Y, test_size=0.33, random_state=42)<jupyter_output><empty_output><jupyter_text>Train classifier<jupyter_code>clf = RandomForestClassifier()
clf.fit(X_train,Y_train)<jupyter_output><empty_output><jupyter_text>Use `models.explainers.ModelExplainer`<jupyter_code>explainer = explainers.ModelExplainer(clf, X_train, model_type='tree')
explainer.explain_global_influence(X_train, nsamples=1000)
explainer.plot_global_explain()
explainer.explain_local_influence(X_valid.iloc[0])
explainer.plot_local_explain(X_valid.iloc[0])
explainer.plot_local_explain_interact(X_valid.iloc[0])
visible_features = ['age','hours-per-week']
explainer.plot_local_explain_interact(X_valid.iloc[0], visible_feat=visible_features)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12214285714285714, 'fraction_numerical': 0.013571428571428571, 'mean_word_length': 12.871287128712872, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '497594', 'license': 'MIT', 'n_tokens_mistral': 529, 'n_tokens_neox': 505, 'n_words': 61, 'path': 'examples/models.explainers_binary_classification_example_adult_dataset.ipynb', 'repo_name': 'Nathanlauga/transparentai', 'size': '1400'}