PARTIALDEPEND Procedure
Example 28.3 Compute a Two-Way Partial Dependence Function
This example shows how to use the PARTIALDEPEND procedure to estimate the partial dependence (PD) function for two analysis variables.
The following DATA step creates the input data table mylib.cars. These statements assume that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
data mylib.cars;
set sashelp.cars;
run;
The following statements run the GRADBOOST procedure to build a gradient boosting model to predict city gas mileage for each automobile in the mylib.cars data table. The procedure also outputs an analytic store named gbStore_cars.
proc gradboost data = mylib.cars seed = 12345;
input Cylinders Horsepower MSRP / level = interval;
input Origin Type / level = nominal;
target MPG_City / level = interval;
saveState rstore = mylib.gbStore_cars;
run;
The following statements run PROC PARTIALDEPEND and output the PD plot with ODS Graphics enabled:
ods graphics on; /* Enables ODS Graphics */
proc PartialDepend data = mylib.cars replicateType = MIDPOINTS seed = 12345;
input Cylinders Horsepower MSRP / level = interval;
input Origin Type / level = nominal;
predictedTarget P_MPG_City;
analysisVariable Type;
analysisVariable Cylinders / min = 3 max = 9 nBins = 3;
astoreModel rstore = mylib.gbStore_cars;
run;
The DATA= option specifies the data table to use for PD analysis. The REPLICATETYPE= option replicates bin midpoints for any numeric analysis variable. The SEED= option specifies the seed to use for pseudorandom number generation. The two INPUT statements specify that the Cylinders, Horsepower, MSRP, Origin, and Type variables be used as inputs. The PREDICTEDTARGET statement specifies that the P_MPG_City variable be used as the predicted target. The first ANALYSISVARIABLE statement specifies that the Type variable be used as an analysis variable. The second ANALYSISVARIABLE statement specifies that the Cylinders variable be used as the second analysis variable. Because Cylinders is an interval variable, its values are binned. The MIN= and MAX= options specify the range of values to bin. The NBINS= option requests three bins. The ASTOREMODEL statement with the RSTORE= option specifies that the analytic store saved in the data table mylib.gbStore_cars be used as the model for analysis.
Output 28.3.1 displays the average predicted mileage for each combination of values of the two analysis variables. It also displays the counts of observations for each combination of values in the sampled data table. Some counts are 0 because the specific combinations do not exist in the sampled training data.
Output 28.3.1: Partial Dependence Table
| Partial Dependence | ||||||
|---|---|---|---|---|---|---|
| Bin (Type) | Bin2 (Cylinders) | Type | Cylinders | Mean Prediction (P_MPG_City) | Standard Error (P_MPG_City) | Count |
| 1 | 1 | Sedan | 4 | 21.789041565 | 0.1542755927 | 96 |
| 1 | 2 | Sedan | 6 | 20.23581313 | 0.1617475483 | 126 |
| 1 | 3 | Sedan | 8 | 19.259887895 | 0.1745958163 | 40 |
| 2 | 1 | SUV | 4 | 19.472021089 | 0.1562924052 | 7 |
| 2 | 2 | SUV | 6 | 17.810132347 | 0.1711337882 | 30 |
| 2 | 3 | SUV | 8 | 16.320553188 | 0.1884769942 | 23 |
| 3 | 1 | Sports | 4 | 21.990765184 | 0.1983879824 | 11 |
| 3 | 2 | Sports | 6 | 21.004352955 | 0.2023398463 | 20 |
| 3 | 3 | Sports | 8 | 19.973304191 | 0.2147457093 | 16 |
| 4 | 1 | Wagon | 4 | 21.228180189 | 0.1884482201 | 14 |
| 4 | 2 | Wagon | 6 | 20.080857321 | 0.1950523097 | 12 |
| 4 | 3 | Wagon | 8 | 18.840263506 | 0.2130501856 | 4 |
| 5 | 1 | Truck | 4 | 20.754898963 | 0.1951855984 | 6 |
| 5 | 2 | Truck | 6 | 17.933089025 | 0.2085177833 | 9 |
| 5 | 3 | Truck | 8 | 17.211059707 | 0.2155960847 | 9 |
| 6 | 1 | Hybrid | 4 | 26.598580576 | 0.2859271912 | 3 |
| 6 | 2 | Hybrid | 6 | 23.693327973 | 0.2936767864 | 0 |
| 6 | 3 | Hybrid | 8 | 22.507343623 | 0.3084082644 | 0 |