Editing
Explainable Ai
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== <span style="color: #FFFFFF;">Applying</span> == '''Computing SHAP values for a gradient boosting model:''' <syntaxhighlight lang="python"> import shap import xgboost as xgb import pandas as pd from sklearn.model_selection import train_test_split # Train a model X, y = shap.datasets.adult() X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) model = xgb.XGBClassifier(n_estimators=100, max_depth=4) model.fit(X_train, y_train) # SHAP explanation explainer = shap.TreeExplainer(model) shap_values = explainer.shap_values(X_test) # Global feature importance shap.summary_plot(shap_values, X_test, plot_type="bar") # Local explanation for one prediction shap.waterfall_plot(shap.Explanation( values=shap_values[0], base_values=explainer.expected_value, data=X_test.iloc[0], feature_names=X_test.columns.tolist() )) </syntaxhighlight> '''Grad-CAM for CNN visual explanation:''' <syntaxhighlight lang="python"> import torch, torch.nn.functional as F from torchvision.models import resnet50, ResNet50_Weights model = resnet50(weights=ResNet50_Weights.IMAGENET1K_V2) model.eval() # Hook on last conv layer to capture gradients and activations activations, gradients = {}, {} model.layer4[-1].register_forward_hook(lambda m, i, o: activations.update({'feat': o})) model.layer4[-1].register_full_backward_hook(lambda m, gi, go: gradients.update({'feat': go[0]})) output = model(input_tensor) model.zero_grad() output[0, output.argmax()].backward() cam = (gradients['feat'] * activations['feat']).mean(dim=[2, 3], keepdim=True) cam = F.relu(cam).squeeze() # Heatmap </syntaxhighlight> ; XAI method by context : '''Tabular, tree models''' β SHAP TreeExplainer (exact, fast) : '''Tabular, any model''' β SHAP KernelExplainer, LIME : '''Image classification''' β Grad-CAM, SHAP GradientExplainer, Integrated Gradients : '''NLP''' β SHAP on tokenized input, attention visualization, LIME for text : '''High-stakes decisions''' β Counterfactual explanations, contrastive explanations : '''Regulatory compliance''' β Model cards, audit trails, decision logs </div> <div style="background-color: #8B4500; color: #FFFFFF; padding: 20px; border-radius: 8px; margin-bottom: 15px;">
Summary:
Please note that all contributions to BloomWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BloomWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information