The HP4SCORE Procedure
Getting Started: HP4SCORE Procedure
This example shows the usage of the HP4SCORE procedure in conjunction with the HPFOREST procedure. The HPFOREST procedure first trains a model on the training data and saves the model as a binary file. The HP4SCORE procedure then uses the trained model to score a different data set.
The following hypothetical data set contains the ratings by three different volunteers on six different proportions of fruits in a fruit punch. The following DATA step creates the SAS data set PunchTrain with the proportions of watermelon, pineapple, orange, and the numerical ratings for each combination of fruit mix and the volunteer:
data PunchTrain;
input watermelon pineapple orange rating;
datalines;
1.0 0.0 0.0 4.3
1.0 0.0 0.0 4.7
1.0 0.0 0.0 4.8
0.0 1.0 0.0 6.2
0.0 1.0 0.0 6.5
0.0 1.0 0.0 6.3
0.5 0.5 0.0 6.3
0.5 0.5 0.0 6.1
0.5 0.5 0.0 5.8
0.0 0.0 1.0 7.0
0.0 0.0 1.0 6.9
0.0 0.0 1.0 7.4
0.5 0.0 0.5 6.1
0.5 0.0 0.5 6.5
0.5 0.0 0.5 5.9
0.0 0.5 0.5 6.2
0.0 0.5 0.5 6.1
0.0 0.5 0.5 6.2
;
run;
The following statements train the forest model on the data set by using the rating as the target and different fruit mix proportions as the independent variables. The SAVE statement saves the model to a binary file punchModel.sav in the current directory. For more information about the HPFOREST procedure options, see Chapter 7, The HPFOREST Procedure.
proc hpforest data=PunchTrain maxtrees=10;
input watermelon pineapple orange;
target rating;
save file="punchModel.sav";
run;
The following DATA step creates the SAS data set PunchScore, which contains only the proportions of watermelon, pineapple, and orange fruit:
data PunchScore;
input watermelon pineapple orange;
datalines;
0.6 0.4 0.0
0.9 0.1 0.0
0.8 0.0 0.2
0.5 0.3 0.2
0.3 0.1 0.6
;
run;
The following statements invoke HP4SCORE to score this data set:
proc hp4score data=PunchScore;
score file="punchModel.sav" out=Scoreout;
run;
proc print data=Scoreout;
run;
The SAS data set Scoreout contains the ratings for each input observation as predicted by the model. Figure 1 shows the scoring results.
Figure 1: Scoreout Output
| Obs | P_rating | _WARN_ |
|---|---|---|
| 1 | 6.07667 | |
| 2 | 5.02167 | |
| 3 | 5.02167 | |
| 4 | 6.07667 | |
| 5 | 6.33000 |