BNET Procedure
Example 5.8 Tuning a Bayesian Network Model
This example illustrates how you can use the AUTOTUNE statement to automatically tune the hyperparameters of a Bayesian network classifier model from observations in the German credit benchmark data, which are available in the sampsio.dmagecr data set. This data set contains 1,000 observations, each of which contains an applicant’s information, including the applicant’s credit rating ("GOOD" or "BAD"). The binary target is named GOOD_BAD. Other input variables are Checking, Duration, History, and so on.
The contents of the sampsio.dmagecr data set are described at http://support.sas.com/documentation/cdl/en/emgs/59885/HTML/default/a001026918.htm.
You can load the sampsio.dmagecr data set into your CAS session by specifying your CAS engine libref in the following DATA step. These statements assume that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
data mylib.dmagecr;
set sampsio.dmagecr;
seed=12345;
if ranuni(seed) < 0.7 then partind=1;
else partind=0;
run;
proc bnet
data=mylib.dmagecr outnetwork=mylib.network;
target Good_Bad;
input Checking History Purpose Savings Employed Installp
Marital Coapp Resident Property Other Housing Existcr
Job Depends Telephon Foreign / level=nominal;
input Age Amount Duration / level=interval;
partition rolevar= PartInd (TRAIN='1' VALIDATE='0');
autotune
/* Tuning Parameters
You do not need to specify any tuning parameters for the default
tuning process. If you want to make adjustments to the default
tuning process, uncomment the following block of code and change
any of the tuning parameters' attributes.
tuningParameters=(
ALPHA ( lb=0.01 ub=0.99 init=0.5 )
INDEPTEST ( values=CHISQUARE GSQUARE MI CHIGSQUARE init=CHIGSQUARE )
MAXPARENTS ( lb=1 ub=5 init=5 )
MIALPHA ( lb=0.0 ub=1.0 init=0.05 )
MISSINGINT ( values=IMPUTE IGNORE init=IGNORE exclude )
MISSINGNOM ( values=IMPUTE IGNORE LEVEL init=IGNORE exclude )
NUMBIN ( lb=2 ub=20 init=5 )
PARENTING ( values=BESTONE BESTSET init=BESTSET )
PRESCREENING ( values=0 1 init=1 )
STRUCTURE ( values=NAIVE TAN PC MB init=PC )
VARSELECT ( values=0 1 2 3 init=1 )
)
*/
;
/* Remove this line to see all results */
ods select BestConfiguration EvaluationHistoryPlot IterationHistoryPlot;
run;
The preceding statements produce the table and the plots shown in Output 5.8.1 through Output 5.8.3. The table in Output 5.8.1 displays the evaluation number, the values of the tuning parameters, and the error metric value for the best Bayesian network classifier model that the tuner found. Note that the ODS SELECT statement limits the displayed results to a single table and two plots. You can remove this statement to display all tables and plots. For the full list of ODS tables that PROC BNET produces, see Table 3.
Output 5.8.1: Best Configuration Table
| Best Configuration | |
|---|---|
| Evaluation | 50 |
| Alpha | 0.90143412 |
| Maximum Number of Parents | 3 |
| Parenting Algorithm | BESTSET |
| Prescreening | ZERO |
| Network Structure | PC |
| Variable Selection | TWO |
| Number of Bins | 7 |
| Mutual Information Alpha | 0.25282 |
| Independence Test Method | CHIGSQUARE |
| Misclassification Error Percentage | 21.97 |
Output 5.8.2 displays a scatter plot of all configurations that the tuner tried. The objective values are shown on the Y axis, and the evaluation numbers are shown on the X axis.
Output 5.8.2: Evaluation History Plot

The plot in Output 5.8.3 displays how the best found objective value and the elapsed time changed with each iteration of the tuner.
Output 5.8.3: Iteration History Plot
