What a Partial-Dependence Plot Shows
A random forest can combine many predictors in ways that are difficult to summarize from its fitted trees alone. A partial-dependence plot (PDP) gives a model-level summary: it shows how the forest’s average prediction changes as one or more selected predictors are set to specified values, while the other predictors are averaged over a reference data set.
The average is the key. A one-predictor PDP does not show predictions for a single policyholder or a single record. At each selected value of the predictor, it makes a modified copy of every reference record, substitutes that value, obtains a forest prediction for each modified record, and averages those predictions. This provides an overall summary for the chosen reference population. It does not, by itself, describe a causal effect or prove that changing a predictor would change an outcome.
In practice, the reference records might be the training data or a specified evaluation sample. The choice matters: changing the reference population can change the average and therefore the plot. A PDP is usually evaluated at a finite grid of values. For a numeric predictor, the grid can use selected values across the observed range; for a factor, it uses its levels. Each plotted point is the calculated average at one grid value.
For a regression forest, \(\hat f\) is the predicted response, so the vertical axis has the response’s units. For a classification forest, a useful PDP generally averages the predicted probability for a specified class. The vertical axis is then a probability. Averaging predicted class labels instead gives a discontinuous fraction of hard classifications and can hide changes in predicted risk.
Why the Averaging Formula Works
The population quantity behind a PDP is the expected model prediction at a fixed selected-predictor value, averaging over the marginal distribution of the other predictors. The empirical formula replaces that expectation with an average over the reference records. Each record contributes one prediction, so every reference record has equal weight in the displayed average.
The justification is direct: if the reference records represent the population of interest, their observed values of \(X_C\) approximate that population’s distribution. Setting \(X_S=z\) for every record holds the selected predictors fixed; averaging the resulting predictions approximates the expectation over \(X_C\). The construction is a model summary, not an estimate of an intervention effect. In particular, when \(X_S\) and \(X_C\) are associated, some modified records may combine predictor values that rarely or never occur together.
Decide whether the forest prediction is a response value or a class probability, and identify which records define the averaging population.
Use meaningful numeric values or available factor levels. Check that the grid does not extend far beyond the data’s support.
For each grid point, replace the selected predictor values in every reference record and obtain one forest prediction per record.
Average the predictions at each grid point, then plot those averages against the selected predictor values. For two selected predictors, display the averages over a grid as a surface or contour plot.
Worked Example: A Regression Forest PDP
A hypothetical insurer fits a regression forest to predict a renewal expense in dollars. The selected predictor is annual mileage, and the other predictors remain at the values of four reference policies. The fitted forest’s predictions after substituting each mileage value are shown below. Construct the one-predictor PDP and describe its shape.
| Reference policy | At 10,000 miles | At 20,000 miles | At 30,000 miles |
|---|---|---|---|
| 1 | 100 | 80 | 90 |
| 2 | 120 | 100 | 110 |
| 3 | 80 | 60 | 70 |
| 4 | 100 | 80 | 90 |
Method. At each mileage value, average the four predictions, retaining the other predictors of each reference policy.
At 10,000 miles, the sum is \(100+120+80+100=400\), so the PDP value is \(400/4=100\) dollars.
At 20,000 miles, the sum is \(80+100+60+80=320\), so the PDP value is \(320/4=80\) dollars.
At 30,000 miles, the sum is \(90+110+70+90=360\), so the PDP value is \(360/4=90\) dollars.
The plotted points are therefore \((10{,}000,100)\), \((20{,}000,80)\), and \((30{,}000,90)\), with mileage in miles and predictions in dollars. The average prediction falls by $20 from 10,000 to 20,000 miles, then rises by $10 from 20,000 to 30,000 miles. The calculation checks: each plotted value is the corresponding column total divided by four. The common mistake this method avoids is averaging across rows for just one mileage value without first replacing mileage in every reference record.
Classification and Multiple Predictors
For a classification forest, use the same substitution-and-average procedure, but specify which class probability is being summarized. The result can be interpreted as the average predicted probability for that class across the reference records at each grid value. It is not the probability for every individual record, and it need not match a class frequency or an observed event rate.
A two-predictor PDP fixes both selected predictors at each pair of grid values. For selected predictors \(S=\{1,2\}\), the empirical calculation is:
A surface or contour plot can reveal whether the model’s average predictions vary differently across combinations of the two selected predictors. However, the same support concern applies: some grid combinations may be unusual in the reference data. A visually smooth surface does not establish that the forest has reliable information for every displayed combination.
Worked Example: A Classification Forest by Channel
A hypothetical insurer uses a classification forest to predict whether a submitted application will require additional review. The selected factor is application channel, with levels Online and Adviser. For four reference applications, the forest gives the following probabilities of additional review after substituting each channel. Calculate the PDP for each level and the difference between them.
| Reference application | Online | Adviser |
|---|---|---|
| 1 | 0.10 | 0.20 |
| 2 | 0.20 | 0.30 |
| 3 | 0.30 | 0.50 |
| 4 | 0.40 | 0.60 |
Method. Average the probability of additional review over the same four reference applications for each factor level.
For Online, the sum is \(0.10+0.20+0.30+0.40=1.00\), giving \(1.00/4=0.25\). For Adviser, the sum is \(0.20+0.30+0.50+0.60=1.60\), giving \(1.60/4=0.40\). The difference, Adviser minus Online, is \(0.40-0.25=0.15\), or 15 percentage points.
Thus, for this forest and reference set, the average predicted probability is 0.15 higher when the channel is set to Adviser rather than Online. The arithmetic checks: the four probabilities in each column sum to the stated totals. The common mistake this method avoids is averaging the predicted class labels (review/no review) instead of the probabilities. The result describes the fitted model’s average predictions; it does not show that changing an application’s channel would cause a 15-point increase.
Correlated Predictors and Sparse Combinations
The main limitation of a PDP arises when the substituted values conflict with the observed relationships among predictors. Suppose age and years at a job are strongly associated. To calculate a PDP for age, the procedure sets every reference record to a selected age while retaining that record’s actual years at the job. Some resulting combinations—such as a very young age with many years at the job—may have little support in the data.
The forest still returns predictions for those combinations, but those predictions may depend on splits and patterns learned from other parts of the data. Because the PDP averages all of them, its curve can reflect unrealistic combinations as well as plausible ones. This concern is especially important when predictors are correlated, when categories are rare, or when a two-predictor grid includes combinations that are sparsely represented.
Worked Example: An Age PDP With Correlated Tenure
Consider a hypothetical forest predicting monthly service cost from customer age and years of tenure. The four reference records have the strongly associated pairs \((25,1)\), \((35,5)\), \((45,15)\), and \((55,25)\), where age is in years and tenure is in years. The forest’s predictions for the age grid, evaluated at each reference record’s retained tenure, are:
| Age set in prediction | Tenure 1 | Tenure 5 | Tenure 15 | Tenure 25 |
|---|---|---|---|---|
| 25 | 12 | 12 | 12 | 12 |
| 35 | 12 | 12 | 20 | 20 |
| 45 | 12 | 20 | 30 | 30 |
| 55 | 20 | 30 | 40 | 50 |
Method. For each age, average all four predictions, retaining the four observed tenure values.
At age 25, the sum is \(12+12+12+12=48\), and the average is \(48/4=12\). At age 35, the sum is \(12+12+20+20=64\), and the average is \(64/4=16\). At age 45, the sum is \(12+20+30+30=92\), and the average is \(92/4=23\). At age 55, the sum is \(20+30+40+50=140\), and the average is \(140/4=35\). The PDP values are therefore 12, 16, 23, and 35; each checks against its row total divided by four.
The age-35 average includes predictions at tenure 15 and 25, even though the observed age-35 reference record has tenure 5. The age-55 average also includes a prediction for age 55 with tenure 1, a combination not represented by the four observed pairs. For comparison, using only the prediction at each observed age-tenure pair would give 12, 12, 30, and 50. That calculation is not the age PDP: it averages over different records at different ages rather than fixing each age and averaging over the same reference tenure values. The PDP is correctly calculated, but its interpretation is limited because some of its combinations are unsupported. The example’s common trap is to treat an average over matching observed pairs as if it were partial dependence.
Reading the Plot With Appropriate Caution
A PDP is useful for communicating the fitted model’s average pattern, but it should be read alongside the data and the modeling purpose. Before interpreting a curve, identify its reference population, the prediction scale, the predictor units, and the range over which the forest has adequate support. If the predictor is numeric, a grid concentrated in a well-populated part of its range can avoid emphasizing extreme values. For factors, note whether some levels occur rarely and whether their averages may be unstable.
A PDP does not show how much predictions vary among individual records at a given grid value. Two forests or two groups of records can have the same average curve while having very different record-level predictions. Also, a flat PDP does not establish that the predictor is unimportant in every part of the predictor space; different patterns can cancel when averaged. These are reasons to treat the plot as a summary, not a complete description of the fitted forest.
Check Your Understanding
For each problem, calculate the requested partial-dependence summary or identify its appropriate interpretation.
- A regression forest gives predictions of 40, 50, and 60 when a selected input is set to 2, using three reference records. What is the PDP value at 2? (Answer: 50)
- A classification forest gives target-class probabilities of 0.12, 0.28, 0.40, and 0.60 at one grid value. Calculate the PDP probability, to four decimals. (Answer: 0.3500)
- For a two-predictor grid point, a forest gives predictions of 5, 9, 12, and 14 for four reference records. What is the two-predictor PDP value at that grid point? (Answer: 10)
- A PDP for vehicle age retains each reference vehicle’s observed mileage, but age and mileage are strongly associated. State the principal limitation of interpreting the curve. (Answer: Some substituted age-mileage combinations may be rare or unsupported, so the averaged predictions may not represent realistic vehicles.)
- At a selected factor level, the forest’s predicted probabilities for three reference records are 0.20, 0.50, and 0.80. A candidate instead averages hard class predictions of 0, 1, and 1. What is the correct PDP probability, and why is the candidate’s calculation different? (Answer: 0.5000; the PDP averages probabilities, whereas the candidate averages thresholded class labels.)