BINNING Procedure
Example 5.5 Tree-Based Binning
(View the complete code for this example.)
The following statements show how you can use the BINNING procedure to perform tree-based binning:
data mylib.hmeq;
set sampsio.hmeq;
run;
proc binning data=mylib.hmeq method=tree;
target bad/level=int;
input mortdue/level = int;
input job/ level = nom;
output outlevelbinmap=mylib.outlevel;
run;
proc print data=mylib.outlevel;
run;
The DATA= option specifies the input data table. The METHOD= option requests that tree-based binning method be used. The TARGET statement specifies bad as the target variable and requests that it be treated as an interval variable. The first INPUT statement names one variable, mortdue, and requests that it be treated as interval. The second INPUT statement names one variable, job, and requests that it be treated as nominal.
Output 5.5.1 shows the "Bin Details" table. Compared to the "Bin Details" tables in previous examples, this table has an extra column, "N Levels". The reason is that other binning methods can handle only interval variables, but tree-based binning can handle both interval and nominal variables. The "N Levels" column shows the number of levels of this variable that this bin contains. As a result, for interval variables, this column is empty.
Output 5.5.1: Bin Details
| Bin Details | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Variable | Bin ID | Lower Bound | Upper Bound | Bin Width | N Levels | Number of Observations | Mean | Standard Deviation | Minimum | Maximum |
| MORTDUE | Missing | 518 | ||||||||
| 1 | -Infty | 37837 | 933 | 23701 | 9087.0 | 2063 | 37750 | |||
| 2 | 37837 | 73611 | 35774 | 2309 | 56416 | 9712.4 | 37843 | 73600 | ||
| 3 | 73611 | 105410 | 31799 | 1283 | 87448 | 9032.3 | 73624 | 105328 | ||
| 4 | 105410 | 145158 | 39749 | 575 | 124127 | 11706 | 105422 | 145127 | ||
| 5 | 145158 | Infty | 342 | 191406 | 48765 | 145324 | 399550 | |||
| JOB | Missing | 1 | 279 | |||||||
| 1 | 2 | 302 | ||||||||
| 2 | 1 | 767 | ||||||||
| 3 | 1 | 2388 | ||||||||
| 4 | 1 | 1276 | ||||||||
| 5 | 1 | 948 | ||||||||
Output 5.5.2 shows the "Transformation Information" table.
Output 5.5.2: Transformation Information
| Transformation Information | |||||
|---|---|---|---|---|---|
| Variable | N | N Miss | N Bins | Importance | Relative Importance |
| MORTDUE | 5442 | 518 | 6 | 8.6977 | 0.5053 |
| JOB | 5681 | 279 | 6 | 17.214 | 1 |
Output 5.5.3 shows the "Output Bin Mapping" data table.
Output 5.5.3: Output Bin Mapping Data Table
| Obs | Variable | Level | BinId |
|---|---|---|---|
| 1 | JOB | 0 | |
| 2 | JOB | Sales | 1 |
| 3 | JOB | Self | 1 |
| 4 | JOB | Mgr | 2 |
| 5 | JOB | Other | 3 |
| 6 | JOB | ProfExe | 4 |
| 7 | JOB | Office | 5 |