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 Pima Indians Diabetes data set is in the UCI Machine Learning Repository (Lichman 2013) and is available at http://archive.ics.uci.edu/ml/datasets/Pima+Indians+Diabetes.[3]The following SAS statements create a SAS data set from a URL:
data diabetes;
%let url=//archive.ics.uci.edu/ml/machine-learning-databases;
infile "http:&url/pima-indians-diabetes/pima-indians-diabetes.data"
device=url delimiter=',';
input NumPregnancies
PlasmaGlucose
DiastolicBloodPr
TricepsSkinfold
HrSerumInsulin
BodyMassIndex
DiabetesPedigreeFn
Age
Diabetes $
;
run;
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;
ods output FitStatistics=fitstats;
save file="model";
run;
Figure 7.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 50. 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 7.1: PROC HPFOREST Getting Started Example Output
| Model Information | ||
|---|---|---|
| Parameter | Value | |
| Variables to Try | 3 | (Default) |
| Maximum Trees | 100 | (Default) |
| 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 |
Figure 7.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 7.2: PROC HPFOREST Getting Started Example Output
Figure 7.3 shows the first 10 and last 10 observations of the fit statistics. When PROC HPFOREST runs in single-machine mode, it 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 the model fluctuates between 0.230 and 0.238, 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 7.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) |
|---|---|---|---|---|---|---|---|
| . | 363 | 0.0448 | 0.1092 | 0.04564 | 0.1107 | 0.9816 | 2.436 |
| . | 735 | 0.0277 | 0.0979 | 0.04664 | 0.1078 | 0.2462 | 2.008 |
| . | 1094 | 0.0232 | 0.1000 | 0.02601 | 0.1137 | 0.1201 | 1.941 |
| . | 1432 | 0.0204 | 0.0954 | 0.02651 | 0.1117 | 0.0822 | 1.743 |
| . | 1782 | 0.0187 | 0.0908 | 0.01829 | 0.1126 | 0.0668 | 1.516 |
| . | 2131 | 0.0176 | 0.0887 | 0.02064 | 0.1110 | 0.0657 | 1.386 |
| . | 2430 | 0.0175 | 0.0852 | 0.01661 | 0.1084 | 0.0677 | 1.198 |
| . | 2817 | 0.0163 | 0.0813 | 0.01527 | 0.1045 | 0.0653 | 1.058 |
| . | 3174 | 0.0156 | 0.0782 | 0.01292 | 0.1021 | 0.0640 | 0.953 |
| . | 3551 | 0.0152 | 0.0777 | 0.01158 | 0.1019 | 0.0638 | 0.899 |
| . | . | . | . | . | . | . | . |
| . | . | . | . | . | . | . | . |
| . | . | . | . | . | . | . | . |
| . | 32740 | 0.0123 | 0.0636 | 0.00185 | 0.0943 | 0.0618 | 0.227 |
| . | 33042 | 0.0124 | 0.0635 | 0.00201 | 0.0940 | 0.0619 | 0.227 |
| . | 33426 | 0.0123 | 0.0635 | 0.00185 | 0.0945 | 0.0618 | 0.227 |
| . | 33794 | 0.0123 | 0.0636 | 0.00201 | 0.0936 | 0.0618 | 0.227 |
| . | 34140 | 0.0123 | 0.0636 | 0.00201 | 0.0940 | 0.0618 | 0.227 |
| . | 34492 | 0.0123 | 0.0635 | 0.00185 | 0.0940 | 0.0617 | 0.224 |
| . | 34846 | 0.0123 | 0.0635 | 0.00218 | 0.0946 | 0.0618 | 0.220 |
| . | 35195 | 0.0123 | 0.0635 | 0.00201 | 0.0941 | 0.0618 | 0.221 |
| . | 35575 | 0.0123 | 0.0635 | 0.00168 | 0.0941 | 0.0618 | 0.221 |
| . | 35921 | 0.0123 | 0.0634 | 0.00168 | 0.0943 | 0.0618 | 0.220 |
Estimates of variable importance appear after the fit statistics. The Number of Rules column in Figure 7.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 7.4: PROC HPFOREST Getting Started Example Output
| Loss Reduction Variable Importance | |||||
|---|---|---|---|---|---|
| Variable | Number of Rules | Gini | OOB Gini | Margin | OOB Margin |
| PlasmaGlucose | 1341 | 0.121668 | 0.04130 | 0.243336 | 0.16453 |
| NumPregnancies | 698 | 0.031116 | -0.01226 | 0.062232 | 0.01934 |
| BodyMassIndex | 1665 | 0.075439 | -0.02387 | 0.150878 | 0.04945 |
| HrSerumInsulin | 815 | 0.029283 | -0.02493 | 0.058566 | 0.00500 |
| TricepsSkinfold | 780 | 0.023756 | -0.02584 | 0.047512 | -0.00134 |
| Age | 1814 | 0.068814 | -0.02874 | 0.137628 | 0.03839 |
| DiastolicBloodPr | 1228 | 0.038636 | -0.03966 | 0.077272 | -0.00008 |
| DiabetesPedigreeFn | 2005 | 0.064256 | -0.05610 | 0.128512 | 0.00764 |
[3] Disclaimer:SAS may reference other websites or content or resources for use at Customer's sole discretion. SAS has no control over any websites or resources that are provided by companies or persons other than SAS. Customer acknowledges and agrees that SAS is not responsible for the availability or use of any such external sites or resources, and does not endorse any advertising, products, or other materials on or available from such websites or resources. Customer acknowledges and agrees that SAS is not liable for any loss or damage that may be incurred by Customer or its end users as a result of the availability or use of those external sites or resources, or as a result of any reliance placed by Customer or its end users on the completeness, accuracy, or existence of any advertising, products, or other materials on, or available from, such websites or resources.
Copyright © SAS Institute Inc. All rights reserved.