Explain Model Action Set

Compute Partial Dependence for Interval Target Variable

This section contains PROC CAS code.

Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts (SAS Viya: Machine Learning Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.

This example shows how to use the partialDependence action to estimate the partial dependence (PD) function for an interval target variable.

The following DATA step creates the input data table mycas.cars in your CAS session. These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

data mycas.cars;
    set sashelp.cars;
run;

The following statements run the gbtreeTrain action in the decisionTree action set to build a gradient boosting model to predict city gas mileage for each automobile in the cars data table. The action also outputs an analytic store named gbStore_cars.

  proc cas;
  action decisionTree.gbtreeTrain /
      table     = {name="cars"},
      inputs    = {{name = "Origin"},
                  {name = "Type"},
                  {name = "Cylinders"},
                  {name = "Horsepower"},
                  {name = "MSRP"}},
      target    = "MPG_City",
      savestate = {name="gbStore_cars", replace=true},
      seed      = 1234
      ;
  run;
  quit;

The following statements run the partialDependence action and output the PD function to an ODS table:

proc cas;
action explainModel.partialDependence  result = pd_res  /
     table            = "cars",
     modelTable       = "gbStore_cars",
     inputs           = {{name = "Origin"},
                         {name = "Type"},
                         {name = "Cylinders"},
                         {name = "Horsepower"},
                         {name = "MSRP"}},
     predictedTarget  = "P_MPG_City",
     analysisVariable = "Type",
     outputTables     = {includeAll=true, replace=true},
     seed             = 1234
     ;
     print pd_res;
run;
quit;

Here, Type is specified as the analysis variable and P_MPG_City is the predicted target. The partialDependence action reads the cars data table and the analytic store created by the gbtreeTrain action and outputs a partial dependence table. Note that the input variables are the same as those specified in the gbtreeTrain action call. Because Type is a string variable, it is treated as nominal, and the output table displays the average predicted city mileage for each level of Type.

Output 13.7.1: Partial Dependence Table

pd_res: Results from explainModel.partialDependence

Partial Dependence
Bin (Type)TypeMean Prediction (P_MPG_City)Standard Error (P_MPG_City)Count
1Sedan20.5446808690.191233923262
2SUV18.1019723720.210293570360
3Sports20.8789891480.217719607549
4Wagon20.1368058120.209453938630
5Truck18.333843350.244997193624
6Hybrid22.7194469070.30188619383


Compute Partial Dependence for Interval Target Variable

This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the cars data to the comma-separated-value (CSV) file cars.csv and then use the following code to load the CSV file into CAS:

s:loadtable{casLib="casuser", path="cars.csv"}

For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.

The following code calls the gbtreeTrain and partialDependence actions. The gbtreeTrain action call builds a gradient boosting model to predict city gas mileage for each automobile in the cars data table and outputs an analytic store named gbStore_cars. The partialDependence action reads the analytic store and outputs the partial dependence (PD) function to an ODS table.


s:loadactionset{actionset="decisionTree"}
s:loadactionset{actionset="explainModel"}

s:decisionTree_gbtreeTrain{
     inputs           = {{name = "Origin"},
                         {name = "Type"},
                         {name = "Cylinders"},
                         {name = "Horsepower"},
                         {name = "MSRP"}},
     savestate        = {name = "gbStore_cars", replace = true},
     table            = {name = "cars"},
     target           = "MPG_City",
     seed             = 1234
}

s:explainModel_partialDependence{
     analysisVariable = "Type",
     inputs           = {{name = "Origin"},
                         {name = "Type"},
                         {name = "Cylinders"},
                         {name = "Horsepower"},
                         {name = "MSRP"}},
     modelTable       = "gbStore_cars",
     outputTables     = {includeAll = true, replace = true},
     predictedTarget  = "P_MPG_City",
     table            = "cars",
     seed             = 1234

In the partialDependence action call, Type is specified as the analysis variable and P_MPG_City is the predicted target. The partialDependence action reads the cars data table and the analytic store created by the gbtreeTrain action and outputs a partial dependence table. Note that the input variables are the same as those specified in the gbtreeTrain action call. Because Type is a string variable, it is treated as nominal, and the output table displays the average predicted city mileage for each level of Type.

Compute Partial Dependence for Interval Target Variable

This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the cars data to the comma-separated-value (CSV) file cars.csv and then use the following code to load the CSV file into CAS:

s.upload_file('cars.csv')

For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.

The following code calls the gbtreeTrain and partialDependence actions. The gbtreeTrain action call builds a gradient boosting model to predict city gas mileage for each automobile in the cars data table and outputs an analytic store named gbStore_cars table. The partialDependence action reads the analytic store and outputs the partial dependence (PD) function to an ODS table.

s.loadactionset("decisionTree")

s.decisionTree.gbtreeTrain (
      table             = {"name":"cars"},
      inputs            = ["Origin", "Type", "Cylinders",
                           "Horsepower", "MSRP"],
      target            = "MPG_City",
      savestate         = {"name":"gbStore_cars", "replace":True},
      seed              = 1234
 )

s.loadactionset("explainModel")

s.explainModel.partialDependence (
       table            = "cars",
       modelTable       = {"name": "gbStore_cars"},
       inputs           = ["Origin", "Type", "Cylinders",
                           "Horsepower", "MSRP"],
       predictedTarget  = "P_MPG_City",
       analysisVariable = "Type",
       outputTables     = {'includeall':True,'replace':True},
       seed             = 1234
 )

In the partialDependence action call, Type is specified as the analysis variable and P_MPG_City is the predicted target. The partialDependence action reads the cars data table and the analytic store created by the gbtreeTrain action, and outputs a partial dependence table. Note that the input variables are the same as those specified in the gbtreeTrain action call. Because Type is a string variable, it is treated as nominal, and the output table displays the average predicted city mileage for each level of Type.

Compute Partial Dependence for Interval Target Variable

This section contains R code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the cars data to the comma-separated-value (CSV) file cars.csv and then use the following code to load the CSV file into CAS:

m <- cas.read.csv(s, "cars.csv", casOut=list(name="cars"))

For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.

The following code calls the gbtreeTrain and partialDependence actions. The gbtreeTrain action call builds a gradient boosting model to predict city gas mileage for each automobile in the cars data table and outputs an analytic store named gbStore_cars. The partialDependence action reads the analytic store and outputs the partial dependence (PD) function to an ODS table.


 loadActionSet(s,'decisionTree')
 loadActionSet(s,'explainModel')

 rs <- cas.decisionTree.gbtreeTrain(
     s,
     inputs    = list('Origin',
                      'Type',
                      'Cylinders',
                      'Horsepower',
                      'MSRP'),
     savestate = list(name='gbStore_cars',replace=true),
     table     = list(name='cars'),
     target    = 'MPG_City',
     seed      = 1234
 )

 rs <- cas.explainModel.partialDependence(
     s,
     analysisVariable = 'Type',
     inputs           = list('Origin',
                             'Type',
                             'Cylinders',
                             'Horsepower',
                             'MSRP'),
     modelTable       = 'gbStore_cars',
     outputTables     = list(includeAll=true,replace=true),
     predictedTarget  = 'P_MPG_City',
     table            = 'cars',
     seed             = 1234
 )


In the partialDependence action call, Type is specified as the analysis variable and P_MPG_City is the predicted target. The partialDependence action reads the cars data table and the analytic store created by the gbtreeTrain action and outputs a partial dependence table. Note that the input variables are the same as those specified in the gbtreeTrain action call. Because Type is a string variable, it is treated as nominal, and the output table displays the average predicted city mileage for each level of Type.

Last updated: August 04, 2026