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

The BART Procedure

Model Information
Data SourceAUTOMPG
Target VariableMPG
DistributionNormal
Number of Trees200
Number of Bins50
Bin MethodQuantiles
Missing RuleSeparate
Burn-In Size100
Simulation Size1000
Thinning Rate1
Random Number Seed246810


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
ClassLevelsValues
Cylinders53 4 5 6 8
Year1370 71 72 73 74 75 76 77 78 79 80 81 82
Origin31 2 3

Number of Observations Read398
Number of Observations Used398


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 Probability0.95
Node Depth Power2
Split Operation Probability0.5
Prune Operation Probability0.5
Leaf Variance Multiplier2
Variance Prior Degrees of Freedom3
Variance Prior Scale1.522001
Variance Prior Quantile Level0.9
Initial Variance Estimate7.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 Kept1000
Proportion of Burn-In Operations Accepted0.22735
Proportion of Sampling Operations Accepted0.21987
Minimum Number of Tree Nodes1
Maximum Number of Tree Nodes15
Average Number of Tree Nodes3.5521
Minimum Tree Depth0
Maximum Tree Depth5
Minimum Number of Leaves1
Maximum Number of Leaves8
Average Number of Leaves2.27605
Minimum Leaf Size5
Maximum Leaf Size398
Average Leaf Size174.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 Error2.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
TaskSecondsPercent
Parsing0.010.08%
Data Preparation0.050.84%
Burn-In Iterations0.559.07%
MCMC Sampling5.4289.81%
Miscellaneous0.010.19%
Cleaning Up0.000.01%
Total6.04100.00%


Last updated: June 22, 2026