BART Procedure
Getting Started: BART Procedure
(View the complete code for this example.)
Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.
This section illustrates some of the basic features of the BART procedure by analyzing data about city-cycle fuel efficiency—that is, the gas mileage of vehicles driven in urban conditions. The data can be downloaded from the UCI Machine Learning Repository (Asuncion and Newman 2007). The following DATA step creates the table autompg in your CAS session:
title 'Automobile MPG Study';
data mylib.Autompg;
input MPG Cylinders Displacement Horsepower Weight
Acceleration Year Origin Name $35.;
datalines;
18.0 8 307.0 130.0 3504 12.0 70 1 Chevrolet Chevelle Malibu
15.0 8 350.0 165.0 3693 11.5 70 1 Buick Skylark 320
18.0 8 318.0 150.0 3436 11.0 70 1 Plymouth Satellite
16.0 8 304.0 150.0 3433 12.0 70 1 AMC Rebel SST
... more lines ...
44.0 4 97.00 52.00 2130 24.6 82 2 VW Pickup
32.0 4 135.0 84.00 2295 11.6 82 1 Dodge Rampage
28.0 4 120.0 79.00 2625 18.6 82 1 Ford Ranger
31.0 4 119.0 82.00 2720 19.4 82 1 Chevy S-10
;
These statements assume that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
The data table contains nine variables. The response variable MPG is city-cycle mileage per gallon (MPG). Seven predictor variables (Cylinders, Displacement, Horsepower, Weight, Acceleration, Year, and Origin) provide vehicle attributes. Among them, Cylinders, Year, and Origin are categorical variables. The last variable, Name, contains the specific name of each vehicle model.
The following statements fit a Bayesian additive regression trees (BART) model:
proc bart data= mylib.autompg seed=246810;
class cylinders year origin;
model mpg = cylinders displacement horsepower
weight acceleration year origin;
run;
The MODEL statement is required when you use the BART procedure to fit a model. If you specify a CLASS statement, it must precede the MODEL statement. The output from this analysis is presented in Figure 1 through Figure 6. Note that this example is run on a single machine with a single chain. If you run PROC BART in a distributed mode, multiple chains are used by default, and the model fit depends on the number of chains that you run.
The "Model Information" in Figure 1 summarizes important information about the model that you fit. Information includes the input data source, response (target) variable, bin method, missing rule, simulation size, thinning rate, and random number seed.
Figure 1: Model Information
| Automobile MPG Study |
| Model Information | |
|---|---|
| Data Source | AUTOMPG |
| Target Variable | MPG |
| Distribution | Normal |
| Number of Trees | 200 |
| Number of Bins | 50 |
| Bin Method | Quantiles |
| Missing Rule | Separate |
| Burn-In Size | 100 |
| Simulation Size | 1000 |
| Thinning Rate | 1 |
| Random Number Seed | 246810 |
Figure 2 displays the "Class Level Information" and "Number of Observations" tables. The "Class Level Information" table lists the levels of the classification variables that you specify in the CLASS statement and the ordering of the levels. The "Number of Observations" table displays the number of observations that are used in the analysis.
Figure 2: Class Level Information and Number of Observations
| Class Level Information | ||
|---|---|---|
| Class | Levels | Values |
| Cylinders | 5 | 3 4 5 6 8 |
| Year | 13 | 70 71 72 73 74 75 76 77 78 79 80 81 82 |
| Origin | 3 | 1 2 3 |
| Number of Observations Read | 398 |
|---|---|
| Number of Observations Used | 398 |
Figure 3 displays the "Prior Information" table. The table summarizes the parameters that define the BART prior for the tree structure and the variance of the response variable. The BART prior parameters typically do not require hyperparameter tuning, because the default BART model tends to perform well in terms of model fit, and this performance does not change significantly if there are small changes in the prior parameters.
Figure 3: Prior Information
| Prior Information | |
|---|---|
| Depth Zero Node Split Probability | 0.95 |
| Node Depth Power | 2 |
| Split Operation Probability | 0.5 |
| Prune Operation Probability | 0.5 |
| Leaf Variance Multiplier | 2 |
| Variance Prior Degrees of Freedom | 3 |
| Variance Prior Scale | 1.522001 |
| Variance Prior Quantile Level | 0.9 |
| Initial Variance Estimate | 7.517741 |
Figure 4 displays the "Sample Information" table. This table summarizes basic information about the posterior samples of the sum-of-trees ensemble, such as the number of samples saved, the proportion of tree-modifying operations accepted, and information about the size of the trees.
Figure 4: Sample Information
| Sample Information | |
|---|---|
| Number of Samples Kept | 1000 |
| Proportion of Burn-In Operations Accepted | 0.22735 |
| Proportion of Sampling Operations Accepted | 0.21987 |
| Minimum Number of Tree Nodes | 1 |
| Maximum Number of Tree Nodes | 15 |
| Average Number of Tree Nodes | 3.5521 |
| Minimum Tree Depth | 0 |
| Maximum Tree Depth | 5 |
| Minimum Number of Leaves | 1 |
| Maximum Number of Leaves | 8 |
| Average Number of Leaves | 2.27605 |
| Minimum Leaf Size | 5 |
| Maximum Leaf Size | 398 |
| Average Leaf Size | 174.8643 |
Figure 5 displays the fit statistics for the fitted model. In this case, there is only one: the average square error (ASE).
Figure 5: Fit Statistics
| Fit Statistics | |
|---|---|
| Average Square Error | 2.89472 |
Finally, PROC BART displays the table shown in Figure 6, which shows the amount of time (in seconds) that it took to perform the various tasks in the analysis.
Figure 6: Procedure Timing
| Task Timing | ||
|---|---|---|
| Task | Seconds | Percent |
| Parsing | 0.01 | 0.08% |
| Data Preparation | 0.05 | 0.84% |
| Burn-In Iterations | 0.55 | 9.07% |
| MCMC Sampling | 5.42 | 89.81% |
| Miscellaneous | 0.01 | 0.19% |
| Cleaning Up | 0.00 | 0.01% |
| Total | 6.04 | 100.00% |