Why Examine Individual Curves?
A partial dependence curve summarizes how a model’s predictions change as one predictor varies, averaging across a reference set of observations. That average is useful, but it can hide an important feature: two observations may have very different prediction profiles even when their average looks simple. In a random forest, for example, one group’s predictions may rise as a feature increases while another group’s predictions remain flat.
Individual conditional expectation (ICE) curves make those profiles visible. Each curve follows one observation through a sequence of hypothetical predictor values, keeping its other recorded predictors fixed. The word “conditional” in the name does not mean that the curve is a causal effect or a conditional expectation of the outcome given the predictor. It describes a model-prediction path constructed for an individual observation.
For a reference sample of \(n\) observations, the finite-sample partial dependence curve at \(z\) is the average of the corresponding ICE predictions:
Thus, partial dependence is not a different set of model evaluations: it is the pointwise average of the individual evaluations. This connection is useful because it lets an analyst compare the average pattern with the variation around that pattern. The reference sample matters: changing which observations are averaged changes the partial dependence curve and the set of ICE curves.
Calculating ICE and Partial Dependence
Worked Example: A Regression Forest with Different Profiles
A hypothetical regression forest predicts claim cost in thousands of dollars. For three reference policies, the model is evaluated at three values of a rating feature \(z\). The resulting predictions are shown below. All other predictors for each policy are held fixed in that policy’s row.
| Policy | \(z=0\) | \(z=1\) | \(z=2\) |
|---|---|---|---|
| 1 | 10 | 12 | 12 |
| 2 | 14 | 14 | 18 |
| 3 | 8 | 11 | 15 |
Step 1: Read each row as an ICE curve. Policy 1’s predictions are \(10,12,12\); policy 2’s are \(14,14,18\); and policy 3’s are \(8,11,15\), in thousands of dollars. The profiles differ: the first becomes flat after \(z=1\), the second is flat initially, and the third rises at both steps.
Step 2: Average predictions at each grid value. At \(z=0\), the mean is \((10+14+8)/3=32/3=10.6667\). At \(z=1\), it is \((12+14+11)/3=37/3=12.3333\). At \(z=2\), it is \((12+18+15)/3=45/3=15\). The partial dependence curve is therefore \(10.6667, 12.3333, 15\) thousand dollars.
Step 3: Compare individual changes with the average. From \(z=0\) to \(z=2\), the three changes are \(12-10=2\), \(18-14=4\), and \(15-8=7\) thousand dollars. Their average is \((2+4+7)/3=13/3=4.3333\) thousand dollars. The partial dependence change is also \(15-10.6667=4.3333\) thousand dollars, subject to rounding.
Check and interpretation. The average curve rises, but it does not describe any one policy’s exact path. In particular, the average change does not imply that every policy’s prediction rises by about \(4.3333\) thousand dollars. The method is to calculate a separate prediction path for each row and average at each grid point. A common mistake is to average the rows first and then treat that one average as if it were an individual profile.
Centering Curves to Compare Changes
ICE curves can begin at different prediction levels. When the main question is how predictions change, rather than what their starting levels are, a centered ICE curve subtracts each observation’s prediction at a chosen reference value \(z_0\):
Every centered curve is zero at \(z_0\). Its value elsewhere is the model-predicted change for that observation relative to the same observation at the reference value. Centering removes differences in starting levels, but it does not remove differences in slopes, steps, or other profile shapes. The reference value should be stated; different choices change the centered values.
For a fixed reference sample and the same \(z_0\), the mean centered ICE value equals the partial dependence change from \(z_0\):
The justification is the distributive property of finite sums: the sum of the differences is the sum of the first terms minus the sum of the second terms. Each resulting sum, divided by \(n\), is the partial dependence value at its respective grid point. This identity provides a useful calculation check: averaging centered changes should give the difference between the two partial dependence values.
Worked Example: Centering Classification-Forest Probabilities
A hypothetical classification forest predicts the probability that a service account will require a specialist review. For three accounts, its predicted probabilities at three values of a numeric feature are as follows. Use \(z_0=0\), and suppose a hard classification labels an account positive when its predicted probability is at least \(0.5\).
| Account | \(z=0\) | \(z=1\) | \(z=2\) |
|---|---|---|---|
| 1 | 0.10 | 0.40 | 0.80 |
| 2 | 0.60 | 0.70 | 0.80 |
| 3 | 0.30 | 0.30 | 0.30 |
Step 1: Calculate the probability-scale partial dependence values. At \(z=0\), the mean is \((0.10+0.60+0.30)/3=1.00/3=0.3333\). At \(z=1\), it is \((0.40+0.70+0.30)/3=1.40/3=0.4667\). At \(z=2\), it is \((0.80+0.80+0.30)/3=1.90/3=0.6333\). These are average predicted probabilities, not proportions of actual future reviews.
Step 2: Center each curve at \(z=0\). Account 1 has changes \(0.10-0.10=0\), \(0.40-0.10=0.30\), and \(0.80-0.10=0.70\). Account 2 has changes \(0\), \(0.70-0.60=0.10\), and \(0.80-0.60=0.20\). Account 3 has changes \(0,0,0\).
Step 3: Check the average centered changes. At \(z=1\), their mean is \((0.30+0.10+0)/3=0.1333\), which equals \(0.4667-0.3333=0.1334\) using the displayed rounded values (the unrounded difference is \(0.1333\)). At \(z=2\), the mean is \((0.70+0.20+0)/3=0.3000\), equal to \(0.6333-0.3333=0.3000\) at four-decimal display precision.
Step 4: Keep the prediction scale clear. At the \(0.5\) classification threshold, the proportions of accounts classified positive are \(1/3\) at \(z=0\), \(1/3\) at \(z=1\), and \(2/3\) at \(z=2\). These are not the probability-scale partial dependence values \(0.3333,0.4667,0.6333\). Averaging hard labels discards information about how far each predicted probability is from the threshold.
Method and trap avoided. Calculate and average the forest’s predicted probabilities if the target summary is probability-scale partial dependence. Do not threshold each prediction first unless the question specifically asks for the proportion classified positive.
What an Average Can Hide
An ICE display is most informative when curves are examined for variation in direction, magnitude, or shape. A single partial dependence curve can conceal offsetting behavior, flat profiles for some observations, or different changes for different subgroups. The next example shows how the overall average can be less informative than the individual and subgroup patterns.
Worked Example: A Flat Average Hiding Opposing Profiles
A hypothetical forest predicts a numeric outcome for four applicants as a score \(z\) changes from 0 to 1 to 2. Applicants 1 and 2 belong to segment A; applicants 3 and 4 belong to segment B. Predictions are in outcome units.
| Applicant | Segment | \(z=0\) | \(z=1\) | \(z=2\) |
|---|---|---|---|---|
| 1 | A | 5 | 7 | 9 |
| 2 | A | 5 | 7 | 9 |
| 3 | B | 5 | 3 | 1 |
| 4 | B | 9 | 7 | 5 |
Step 1: Compute the overall partial dependence values. At \(z=0\), the mean is \((5+5+5+9)/4=24/4=6\). At \(z=1\), it is \((7+7+3+7)/4=24/4=6\). At \(z=2\), it is \((9+9+1+5)/4=24/4=6\). The overall partial dependence curve is flat.
Step 2: Calculate centered individual changes. Relative to \(z=0\), applicants 1 and 2 each have changes \(0,2,4\). Applicant 3 has changes \(0,-2,-4\), and applicant 4 has changes \(0,-2,-4\). The profiles do not support the interpretation that the modeled feature has no prediction relationship for every applicant.
Step 3: Compare segments. Segment A’s mean predictions are \((5+5)/2=5\), \((7+7)/2=7\), and \((9+9)/2=9\): its average rises by 4 units from \(z=0\) to \(z=2\). Segment B’s means are \((5+9)/2=7\), \((3+7)/2=5\), and \((1+5)/2=3\): its average falls by 4 units. With two applicants in each segment, the changes cancel in the overall average.
Check and interpretation. The overall mean is correctly calculated, but the flat curve alone does not reveal the opposing segment patterns. The suitable interpretation is that the average prediction is unchanged over this grid for this reference sample, while individual and segment profiles vary substantially. ICE reveals the heterogeneity; it does not, by itself, establish why it occurs.
Generating ICE Predictions in R
For a fitted forest, ICE calculations require repeated prediction on modified versions of the reference data. For each grid value, copy the reference rows, replace the focal predictor in every row by that value, and obtain the model predictions. Store each result with its original row identifier and grid value. The resulting table has one prediction for each observation-grid combination.
Use a stated subset or the full analysis sample, and select focal-feature values that are meaningful for the model and the intended interpretation.
For each grid value, copy the reference data and replace only the focal predictor. Preserve all other predictors row by row.
Obtain the forest prediction for every modified row. For a classification forest, specify whether the required output is a class probability or a hard class.
Connect predictions for each row across the grid to form ICE curves; calculate the pointwise mean to obtain the corresponding partial dependence curve. If useful, subtract each row’s prediction at a stated reference grid value.
In R, this can be implemented with a loop over the grid and the fitted model’s prediction method. For a ranger regression forest, the prediction values are available from the returned prediction object; for classification, request or extract class probabilities when that is the intended scale. The exact prediction call depends on how the model was fitted and the outcome type. The essential operation is the same: replace the focal column in a copy of the reference data, predict, and retain the row-to-curve correspondence.
Tree-based forest predictions are typically stepwise in a numeric predictor: changing its value may leave a row’s prediction unchanged until a tree split is crossed. ICE curves therefore need not look smooth. A fine grid can show steps more clearly, but it does not create additional information or justify interpreting every grid point as a distinct meaningful state.
Interpretation Limits and Common Traps
An ICE curve is a description of a fitted model’s predictions under a particular set of substitutions. It is not an estimate of an individual’s causal response to changing the predictor. A model may use associations in its training data, and changing one predictor while freezing the others does not represent an intervention unless additional causal assumptions and a suitable design justify that interpretation.
- Unsupported combinations: If the focal predictor is correlated with other predictors, replacing it while keeping those predictors fixed can create combinations rarely or never observed. The forest still returns a prediction, but it may be unreliable in that region. Check whether the grid and modified records are supported by the data.
- Averages can conceal variation: A flat partial dependence curve can result from opposing increases and decreases, as in the example above. Inspect ICE profiles, and consider describing relevant groups when justified by the analysis.
- Reference sample changes the summary: An average over a selected subset describes that subset’s predictions. A different reference population can produce a different partial dependence curve.
- Scale matters: For classification, distinguish predicted probability from a thresholded class. For regression, state the outcome units. Curves on different scales answer different questions.
- Do not overread curve crossings: Crossings indicate differences in model-predicted profiles on the chosen grid. They do not, by themselves, establish a real-world interaction or a causal effect.
Check Your Understanding
For each problem, calculate the requested summary from the supplied model predictions and state what the result does or does not show.
- A regression forest gives two reference records predictions \((6,9,12)\) and \((12,9,6)\) at grid values \(z=0,1,2\). Calculate the partial dependence value at each grid point and the centered ICE changes for both records using \(z_0=0\). (Answer: Partial dependence is \(9,9,9\); centered changes are \((0,3,6)\) and \((0,-3,-6)\), so the flat average hides opposing profiles.)
- A forest’s probability predictions for three records are \((0.2,0.4)\), \((0.4,0.5)\), and \((0.6,0.5)\) at \(z=0,1\), respectively. Calculate the probability-scale partial dependence at both values and its change. (Answer: \(0.4000\) at \(z=0\), \(0.4667\) at \(z=1\), change \(0.0667\).)
- At two grid values, a model gives one record predictions of 20 and 25, and another record predictions of 30 and 27. Find both centered changes from the first grid value and the partial dependence change. (Answer: The centered changes are \(+5\) and \(-3\); the mean change, and partial dependence change, is \((5-3)/2=+1\).)
- A classification forest gives probabilities \(0.2,0.6,0.8\) for three records at a grid point. With a positive-class threshold of \(0.5\), calculate the mean probability and the proportion classified positive. Explain why they differ. (Answer: Mean probability is \(1.6/3=0.5333\); the proportion classified positive is \(2/3=0.6667\), because thresholding discards the probability values’ distances from the threshold.)
- A focal feature is strongly associated with another predictor. An ICE calculation changes the focal feature across a broad grid while leaving the associated predictor at each record’s observed value. What interpretive check is needed before treating the resulting curve as informative? (Answer: Check whether the modified predictor combinations are supported by observed data; unsupported combinations can make the model’s returned predictions unreliable and do not establish causal effects.)