What is Explainable AI (XAI) and how do you implement model interpretability?
Explainable AI provides human-understandable explanations for model predictions. Importance: regulatory compliance (GDPR right to explanation, Fair Credit Reporting Act), building user trust, debugging model errors, and identifying biases. Methods: (1) SHAP (SHapley Additive exPlanations): game-theoretic approach assigning each feature a contribution to the prediction. Works for any model. Produces both local explanations (per prediction) and global explanations (overall feature importance). (2) LIME (Local Interpretable Model-agnostic Explanations): creates a simple interpretable model (linear) that approximates the complex model's behavior around a specific prediction. (3) Attention visualization: for transformer models, visualize attention weights to show which input tokens the model focused on (useful but not always a reliable explanation). (4) Integrated Gradients: attributes predictions to input features by accumulating gradients along a path from a baseline to the input. (5) Counterfactual explanations: show what minimal changes to the input would change the prediction (e.g., "if your income were $5000 higher, the loan would be approved"). Implementation: SHAP for tabular data (TreeExplainer for tree models is exact and fast, KernelExplainer for any model but slower), LIME for text and image explanations, and Captum (PyTorch) or tf-explain (TensorFlow) for deep learning interpretability. Production: precompute explanations for common prediction types, cache explanations for repeated queries, implement explanation APIs alongside prediction APIs, and present explanations in user-appropriate formats (feature importance bars for analysts, natural language for end users). Validation: verify that explanations are faithful (accurately reflect model behavior), consistent (similar inputs get similar explanations), and useful (stakeholders can act on them).