Partial Dependence and ICE Curves

easy
Unit 7 · Interpretability I0/5 to milestone

How does a model's prediction change as one feature varies? Partial dependence sets that feature to each grid value for every row and averages the predictions. ICE (individual conditional expectation) curves keep the per-row predictions, which reveals interactions that averaging hides.

model is any function mapping a 2-D array to a 1-D array of predictions. Implement:

  • ice_curves(model, X, feature, grid): an array of shape (n_rows, len(grid)). Don't modify X.
  • partial_dependence(model, X, feature, grid): the mean over rows
  • heterogeneity(model, X, feature, grid): the mean standard deviation across rows of the centred ICE curves (each curve minus its own value at the first grid point). 0 means the feature acts the same way for everyone.
#interpretability#model-agnostic#explainability2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Partial Dependence and ICE Curves · TechGradify