# Model Complexity vs. Interpretability

> More complex models are generally more accurate but harder to understand and audit. Linear models vs. tree ensembles vs. neural networks and post-hoc interpretation methods.

- **Category**: Trade-offs
- **Subcategory**: Machine Learning
- **Canonical URL**: https://designpattern.fyi/trade_offs/model-complexity-vs-interpretability/

---

## Description
**Intent**: Balance model accuracy against the ability to understand and explain model decisions, especially important in regulated industries and high-stakes applications.

**Context**: Simple models (linear regression, decision trees) are highly interpretable but may have lower accuracy. Complex models (deep neural networks, ensembles) achieve higher accuracy but are black boxes. In regulated industries (finance, healthcare), interpretability is often required. Post-hoc methods (SHAP, LIME) can help interpret complex models but have limitations.

**Solution**: Start with interpretable models in regulated industries. Use SHAP/LIME for model debugging regardless of interpretability requirements. Use attention maps for neural networks (with caution). Consider integrated gradients for differentiable models. Use counterfactual explanations for "what-if" scenarios. Accept that accuracy-interpretability trade-off is shrinking but hasn't disappeared.



## Use Cases
Credit scoring using logistic regression for regulatory compliance and explainability. Medical diagnosis using random forests with SHAP values for feature importance. Fraud detection using gradient boosting with LIME for individual case explanations.



## Implementation Example

```python
# Model Complexity vs. Interpretability

from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
import shap
import lime
import lime.lime_tabular

# Simple, Interpretable Model
simple_model = LogisticRegression()
simple_model.fit(X_train, y_train)

# Feature importance directly available
print("Feature coefficients:", simple_model.coef_)

# Complex, Accurate Model
complex_model = RandomForestClassifier(n_estimators=100, max_depth=10)
complex_model.fit(X_train, y_train)

# Post-hoc interpretation with SHAP
explainer = shap.TreeExplainer(complex_model)
shap_values = explainer.shap_values(X_test)

# Global feature importance
shap.summary_plot(shap_values, X_test)

# Local explanation for single prediction
shap.force_plot(explainer.expected_value[1], shap_values[1][0], X_test.iloc[0])

# Post-hoc interpretation with LIME
lime_explainer = lime.lime_tabular.LimeTabularExplainer(
    X_train.values,
    feature_names=feature_names,
    class_names=classes,
    discretize_continuous=True
)

# Local explanation
exp = lime_explainer.explain_instance(
    X_test.iloc[0].values,
    complex_model.predict_proba,
    num_features=5
)
exp.show_in_notebook()

```



## Trade-offs


### Advantages

- Clear framework for accuracy vs. explainability trade-off

- Post-hoc methods enable interpretation of complex models

- Regulatory compliance drives need for interpretability

- SHAP provides theoretical guarantees for feature attribution




### Considerations & Drawbacks

- Post-hoc explanations may not reflect true model reasoning

- Complex models still hard to fully interpret

- Different interpretation methods can give different results

- Interpretability requirements can limit model performance







