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 rowsheterogeneity(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.