The HPFOREST Procedure
Getting Started: HPFOREST Procedure
This example uses diabetes data to illustrate PROC HPFOREST. Diabetes is a major American disease. The American Diabetes Association estimates that over 8% of Americans have diabetes, and diabetes costs Americans over $175 billion a year. The National Institute of Diabetes and Digestive and Kidney Diseases (NIDDK) has been studying diabetes and obesity in the Akimel O’otham (formerly known as Pima Indians) in Arizona for over 30 years. Smith et al. (1988) prepared some of the NIDDK data for forecasting the onset of diabetes and then donated the data for community use. Since then, the data have been applied to dozens of experimental algorithms for predicting the onset of diabetes.
The following SAS statements create a SAS data set:
data diabetes;
input NumPregnancies
PlasmaGlucose
DiastolicBloodPr
TricepsSkinfold
HrSerumInsulin
BodyMassIndex
DiabetesPedigreeFn
Age
Diabetes $;
datalines;
6 148 72 35 0 33.6 0.627 50 2
1 85 66 29 0 26.6 0.351 31 1
8 183 64 0 0 23.3 0.672 32 2
1 89 66 23 94 28.1 0.167 21 1
0 137 40 35 168 43.1 2.288 33 2
5 116 74 0 0 25.6 0.201 30 1
3 78 50 32 88 31.0 0.248 26 2
10 115 0 0 0 35.3 0.134 29 1
2 197 70 45 543 30.5 0.158 53 2
... more lines ...
2 122 70 27 0 36.8 0.340 27 1
5 121 72 23 112 26.2 0.245 30 1
1 126 60 0 0 30.1 0.349 47 2
1 93 70 31 0 30.4 0.315 23 1
;
The variable diabetes has values 0 and 1, 1 indicating the presence of diabetes. The other variables are raw measures on interval scales, except for DiabetesPedigreeFn, which is an interval variable created by Smith et al. (1988) to capture the family history of diabetes. PROC HPFOREST uses an interval scale for numeric variables and a nominal scale for categorical variables unless the scale is specified. The following statements run PROC HPFOREST and save the model in a binary file:
proc hpforest data=diabetes ;
input NumPregnancies
PlasmaGlucose
DiastolicBloodPr
TricepsSkinfold
HrSerumInsulin
BodyMassIndex
DiabetesPedigreeFn
Age ;
target Diabetes / level=binary;
ods output FitStatistics=fitstats;
save file="model";
run;
Figure 1 shows that the program ran locally and that four threads were used. The default number of threads is the number of processors in the computer. The listing also shows the values of the training parameters and the number of observations (768). No parameters are specified in the PROC HPFOREST statement; therefore, all the values are default. The maximum number of decision trees to create is 100. The VARS_TO_TRY= option value is 3, indicating that three of the eight input variables are randomly selected to be considered for a splitting rule.
Figure 1: PROC HPFOREST Getting Started Example Output
| Performance Information | |
|---|---|
| Execution Mode | Single-Machine |
| Number of Threads | 16 |
| Data Access Information | |||
|---|---|---|---|
| Data | Engine | Role | Path |
| WORK.DIABETES | V9 | Input | On Client |
| Model Information | ||
|---|---|---|
| Parameter | Value | |
| Variables to Try | 3 | (Default) |
| Maximum Trees | 100 | (Default) |
| Actual Trees | 100 | |
| Inbag Fraction | 0.6 | (Default) |
| Prune Fraction | 0 | (Default) |
| Prune Threshold | 0.1 | (Default) |
| Leaf Fraction | 0.00001 | (Default) |
| Leaf Size Setting | 1 | (Default) |
| Leaf Size Used | 1 | |
| Category Bins | 30 | (Default) |
| Interval Bins | 100 | |
| Minimum Category Size | 5 | (Default) |
| Node Size | 100000 | (Default) |
| Maximum Depth | 20 | (Default) |
| Alpha | 1 | (Default) |
| Exhaustive | 5000 | (Default) |
| Rows of Sequence to Skip | 5 | (Default) |
| Split Criterion | . | Gini |
| Preselection Method | . | BinnedSearch |
| Missing Value Handling | . | Valid value |
| Number of Observations | |
|---|---|
| Type | N |
| Number of Observations Read | 768 |
| Number of Observations Used | 768 |
Figure 2 shows the baseline fit statistics. PROC HPFOREST first computes baseline statistics without using a model. The listing shows a baseline misclassification rate of 0.349, because that is the proportion of observations for which the value of diabetes is 1.
Figure 2: PROC HPFOREST Getting Started Example Output
| Baseline Fit Statistics | |
|---|---|
| Statistic | Value |
| Average Square Error | 0.227 |
| Misclassification Rate | 0.349 |
| Log Loss | 0.647 |
Figure 3 shows the first 10 and last 10 observations of the fit statistics. PROC HPFOREST computes fit statistics for a sequence of forests that have an increasing number of trees. As the number of trees increases, the fit statistics usually improve (decrease) at first and then level off and fluctuate in a small range. Forest models provide an alternative estimate of average square error and misclassification rate, called the out-of-bag (OOB) estimate. The OOB estimate is a convenient substitute for an estimate that is based on test data and is a less biased estimate of how the model will perform on future data. For more information, see the section Bagging the Data. The listing shows that the OOB error estimate is worse (larger) than the estimate that evaluates all observations on all trees. This is usual. The OOB misclassification rate for models with many trees fluctuates between 0.233 and 0.240, which is in a range much less than the baseline rate of rate of 0.349. Therefore, you can conclude that the model is good.
Figure 3: PROC HPFOREST Getting Started Example Output
| Number of Trees | Number of Leaves | Average Square Error (Train) | Average Square Error (OOB) | Misclassification Rate (Train) | Misclassification Rate (OOB) | Log Loss (Train) | Log Loss (OOB) |
|---|---|---|---|---|---|---|---|
| 1 | 89 | 0.1510 | 0.377 | 0.1510 | 0.377 | 3.478 | 8.672 |
| 2 | 196 | 0.0837 | 0.323 | 0.1328 | 0.339 | 0.865 | 7.067 |
| 3 | 314 | 0.0590 | 0.286 | 0.0664 | 0.324 | 0.258 | 5.848 |
| 4 | 413 | 0.0504 | 0.270 | 0.0599 | 0.310 | 0.194 | 5.129 |
| 5 | 526 | 0.0472 | 0.257 | 0.0378 | 0.311 | 0.167 | 4.302 |
| 6 | 631 | 0.0419 | 0.240 | 0.0352 | 0.293 | 0.156 | 3.718 |
| 7 | 737 | 0.0397 | 0.233 | 0.0273 | 0.288 | 0.155 | 3.429 |
| 8 | 844 | 0.0385 | 0.229 | 0.0286 | 0.286 | 0.155 | 3.173 |
| 9 | 958 | 0.0356 | 0.214 | 0.0169 | 0.276 | 0.150 | 2.741 |
| 10 | 1056 | 0.0346 | 0.204 | 0.0182 | 0.268 | 0.148 | 2.494 |
| . | . | . | . | . | . | . | . |
| . | . | . | . | . | . | . | . |
| . | . | . | . | . | . | . | . |
| 91 | 9545 | 0.0262 | 0.161 | 0.0000 | 0.228 | 0.140 | 0.567 |
| 92 | 9657 | 0.0262 | 0.161 | 0.0000 | 0.230 | 0.140 | 0.568 |
| 93 | 9761 | 0.0262 | 0.161 | 0.0000 | 0.225 | 0.140 | 0.567 |
| 94 | 9869 | 0.0262 | 0.161 | 0.0000 | 0.228 | 0.140 | 0.568 |
| 95 | 9980 | 0.0262 | 0.161 | 0.0000 | 0.225 | 0.140 | 0.566 |
| 96 | 10076 | 0.0263 | 0.161 | 0.0000 | 0.229 | 0.141 | 0.566 |
| 97 | 10181 | 0.0263 | 0.161 | 0.0000 | 0.228 | 0.140 | 0.565 |
| 98 | 10295 | 0.0262 | 0.161 | 0.0000 | 0.228 | 0.140 | 0.565 |
| 99 | 10410 | 0.0262 | 0.161 | 0.0000 | 0.227 | 0.140 | 0.564 |
| 100 | 10515 | 0.0261 | 0.160 | 0.0000 | 0.228 | 0.140 | 0.563 |
Estimates of variable importance appear after the fit statistics. The Number of Rules column in Figure 4 shows the number of splitting rules that use a variable. The section Measuring Variable Importance explains the measures of importance. Each measure is computed twice: once on training data and once on out-of-bag data. As with fit statistics, the out-of-bag estimates are less biased. The rows are sorted by the OOB Gini measure, which is a more stringent measure than the OOB margin measure. The OOB Gini column is negative for seven variables, and the OOB margin column is negative for two variables. The splitting rules that involve these two variables are, on average, spurious. The main conclusion from fitting the forest model to these data is that plasmaGlucose is the most important predictor of future onset of diabetes.
Figure 4: PROC HPFOREST Getting Started Example Output
| Loss Reduction Variable Importance | |||||
|---|---|---|---|---|---|
| Variable | Number of Rules | Gini | OOB Gini | Margin | OOB Margin |
| PlasmaGlucose | 1331 | 0.122545 | 0.04123 | 0.245089 | 0.16359 |
| NumPregnancies | 747 | 0.031608 | -0.01338 | 0.063216 | 0.01889 |
| HrSerumInsulin | 883 | 0.031949 | -0.02141 | 0.063898 | 0.00871 |
| BodyMassIndex | 1682 | 0.077170 | -0.02385 | 0.154340 | 0.05160 |
| TricepsSkinfold | 736 | 0.022025 | -0.02570 | 0.044049 | -0.00292 |
| Age | 1754 | 0.066089 | -0.02916 | 0.132177 | 0.03828 |
| DiastolicBloodPr | 1234 | 0.038067 | -0.03653 | 0.076134 | 0.00326 |
| DiabetesPedigreeFn | 2048 | 0.065277 | -0.05501 | 0.130555 | 0.00954 |