Explain Model Action Set

Build a Global Surrogate Regression Model Using the linearExplainer Action

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 Visual Data Mining and 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 runs the linearExplainer action to build a global surrogate model of a forest model by using the global regression method.

The following DATA step creates the reference data table mycas.dmagecr in your CAS session, keeping only the variables age, amount, coapp, duration, foreign, job, and good_bad. These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

data mycas.dmagecr;
    set sampsio.dmagecr;
    keep age amount coapp duration foreign job good_bad;
run;

The following DATA step creates the query data table mycas.query in your CAS session:

data mycas.query;
   set sampsio.dmagecr;
   keep age amount coapp duration foreign job good_bad;
   if _N_ = 20;
run;

The following statements run the forestTrain action in the decisionTree action set to build a forest model in order to predict whether the credit rating of each individual in the dmagecr data table is good or bad. The action also outputs an analytic store named forest_astore.

proc cas;
   loadactionset "decisionTree";
   decisionTree.forestTrain   result    = r
                            / table     = 'DMAGECR'
                              seed      = 1234
                              saveState = {name    = 'FOREST_ASTORE',
                                           replace = True}
                              target    = 'good_bad'
                              maxLevel  = 5
                              inputs    = {{name   = "age"},
                                           {name   = "amount"},
                                           {name   = "coapp"},
                                           {name   = "duration"},
                                           {name   = "foreign"},
                                           {name   = "job"}}
                              nominals  = {{name   = "coapp"},
                                           {name   = "foreign"},
                                           {name   = "job"}}
                              ;
   run;
quit;

The following statements run the linearExplainer action and output the results to ODS tables:

proc cas;
   loadactionset "explainModel";
   explainModel.linearExplainer / table            = "DMAGECR"
                                  query            = "QUERY"
                                  modelTable       = "FOREST_ASTORE"
                                  modelTableType   = "ASTORE"
                                  predictedTarget  = "P_good_badbad"
                                  seed             = 1234
                                  preset           = "GLOBALREG"
                                  inputs           = {{name = "age"},
                                                      {name = "amount"},
                                                      {name = "coapp"},
                                                      {name = "duration"},
                                                      {name = "foreign"},
                                                      {name = "job"}}
                                  nominals         = {{name = "coapp"},
                                                      {name = "foreign"},
                                                      {name = "job"}}
                                  ;
   run;
quit;

The table parameter names the input reference data table. The query parameter names the input query data table. The modelTable parameter names the model table. The modelTableType parameter specifies that the model table is an analytic store model table. The predictedTarget parameter specifies that the variable P_good_badbad be used as the predicted target variable. The seed parameter specifies the seed to use for pseudorandom number generation. The preset parameter specifies that the preset explanation method is the global regression method. The inputs parameter specifies that the variables age, amount, coapp, duration, foreign, and job be used as inputs. The nominals parameter specifies that the variables coapp, foreign, and job be used as nominal variables.

The "Explainer Information" table, "Parameter Estimates" table, and "Explainer Fidelity" table that these statements produce are shown in Output 11.3.1, Output 11.3.2, and Output 11.3.3, respectively.

Output 11.3.1: Explainer Information

Results from explainModel.linearExplainer

Explainer Information
RowIdDescriptioncValueValue
DATAGENData Generation MethodNone.
DISTANCEDistance MethodUniform.
EXPLAINERExplainer TypeRegression.
BINARYENCODINGBinary EncodingNone.
STANDARDIZEStandardize Parameter EstimatesNone.
INCLUDEMISSINGInclude Missing as a LevelNo.
SEEDSeed12341234


Output 11.3.2: Explainer Parameter Estimates

Parameter Estimates
VariablecoappforeignjobEstimateQueryValue
Intercept...0.2710162596.
age...-0.00176132931
amount...0.00001367123430
coapp2..0.0508472870
coapp3..-0.0313322240
coapp1..01
duration...0.002470825224
foreign.2.-0.0863770520
foreign.1.01
job..10.01836309340
job..20.00214810520
job..4-0.0052739330
job..301


Output 11.3.3: Explainer Fidelity Information

Explainer Fidelity
ModelPredExplainerPredExplainerRMSE
0.29455725280.32260717390.0442600396


Build a Global Surrogate Regression Model Using the linearExplainer Action

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 dmagecr data to the comma-separated-value (CSV) file dmagecr.csv, convert the query data to the CSV file query.csv, and then use the following code to load the CSV files into CAS:

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

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

This example runs the linearExplainer action to build a global surrogate model of a forest model by using the global regression method. The following code runs the forestTrain action in the decisionTree action set to build a forest model in order to predict whether the credit rating of each individual in the dmagecr data table is good or bad. The action also outputs an analytic store named forest_astore.


                              table     = {name ="DMAGECR"},
                              seed      = 1234,
                              saveState = {name    = 'FOREST_ASTORE',
                                           replace = True},
                              target    = 'good_bad',
                              maxLevel  = 5,
                              inputs    = {{name   = "age"},
                                           {name   = "amount"},
                                           {name   = "coapp"},
                                           {name   = "duration"},
                                           {name   = "foreign"},
                                           {name   = "job"}},
                              nominals  = {{name   = "coapp"},
                                           {name   = "foreign"},
                                           {name   = "job"}}

The following code runs the linearExplainer action:

                              table            = {name="DMAGECR"},
                              query            = {name="QUERY"},
                              modelTable       = {name="FOREST_ASTORE"},
                              modelTableType   = "ASTORE",
                              predictedTarget  = "P_good_badbad",
                              seed             = 1234,
                              preset           = "GLOBALREG",
                              inputs           = {{name = "age"},
                                                  {name = "amount"},
                                                  {name = "coapp"},
                                                  {name = "duration"},
                                                  {name = "foreign"},
                                                  {name = "job"}},
                              nominals         = {{name = "coapp"},
                                                  {name = "foreign"},
                                                  {name = "job"}}

The table parameter names the input reference data table. The query parameter names the input query data table. The modelTable parameter names the model table. The modelTableType parameter specifies that the model table is an analytic store model table. The predictedTarget parameter specifies that the variable P_good_badbad be used as the predicted target variable. The seed parameter specifies the seed to use for pseudorandom number generation. The preset parameter specifies that the preset explanation method is the global regression method. The inputs parameter specifies that the variables age, amount, coapp, duration, foreign, and job be used as inputs. The nominals parameter specifies that the variables coapp, foreign, and job be used as nominal variables.

For example output from the action, see the SAS code examples.

Build a Global Surrogate Regression Model Using the linearExplainer Action

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 dmagecr data to the comma-separated-value (CSV) file dmagecr.csv, convert the query data to the CSV file query.csv, and then use the following code to load the CSV files into CAS:

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

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

This example runs the linearExplainer action to build a global surrogate model of a forest model by using the global regression method. The following code runs the forestTrain action in the decisionTree action set to build a forest model in order to predict whether the credit rating of each individual in the dmagecr data table is good or bad. The action also outputs an analytic store named forest_astore.


   s,
   table     = list(name ="DMAGECR"),
   seed      = 1234,
   saveState = list(name = 'FOREST_ASTORE',
                    replace = True),
   target    = 'good_bad',
   maxLevel  = 5,
   inputs    = list("age",
                    "amount",
                    "coapp",
                    "duration",
                    "foreign",
                    "job"),
   nominals  = list("coapp",
                    "foreign",
                    "job")

The following code runs the linearExplainer action:

   s,
   table            = list(name="DMAGECR"),
   query            = list(name="QUERY"),
   modelTable       = list(name="FOREST_ASTORE"),
   modelTableType   = "ASTORE",
   predictedTarget  = "P_good_badbad",
   seed             = 1234,
   preset           = "GLOBALREG",
   inputs           = list("age",
                           "amount",
                           "coapp",
                           "duration",
                           "foreign",
                           "job"),
   nominals         = list("coapp",
                           "foreign",
                           "job")

The table parameter names the input reference data table. The query parameter names the input query data table. The modelTable parameter names the model table. The modelTableType parameter specifies that the model table is an analytic store model table. The predictedTarget parameter specifies that the variable P_good_badbad be used as the predicted target variable. The seed parameter specifies the seed to use for pseudorandom number generation. The preset parameter specifies that the preset explanation method is the global regression method. The inputs parameter specifies that the variables age, amount, coapp, duration, foreign, and job be used as inputs. The nominals parameter specifies that the variables coapp, foreign, and job be used as nominal variables.

For example output from the action, see the SAS code examples.

Build a Global Surrogate Regression Model Using the linearExplainer Action

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 dmagecr data to the comma-separated-value (CSV) file dmagecr.csv, convert the query data to the CSV file query.csv, and then use the following code to load the CSV files into CAS:

s.upload_file('dmagecr.csv')
s.upload_file('query.csv')

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

This example runs the linearExplainer action to build a global surrogate model of a forest model by using the global regression method. The following code runs the forestTrain action in the decisionTree action set to build a forest model in order to predict whether the credit rating of each individual in the dmagecr data table is good or bad. The action also outputs an analytic store named forest_astore.

s.loadactionset(actionset="decisionTree")
s.forestTrain(
  table           = {"name" : "DMAGECR"},
  seed            = 123,
  inputs          = ["age", "amount", "coapp", "duration",
                     "foreign", "job"],
  target          = "good_bad",
  nominals        = ["coapp", "foreign", "job"],
  maxLevel        = 5,
  saveState       = {"name" : "FOREST_ASTORE", "replace" : True}
 )

The following code runs the linearExplainer action:

s.loadactionset(actionset="explainModel")
s.linearExplainer(
  table           = {"name" : "DMAGECR"},
  query           = {"name" : "QUERY"},
  modelTable      = {"name" : "FOREST_ASTORE"},
  modelTableType  = "ASTORE",
  predictedTarget = "P_good_badbad",
  seed            = 1234,
  preset          = "GLOBALREG",
  inputs          = ["age", "amount", "coapp", "duration",
                     "foreign", "job"],
  nominals        = ["coapp", "foreign", "job"]
 )

The table parameter names the input reference data table. The query parameter names the input query data table. The modelTable parameter names the model table. The modelTableType parameter specifies that the model table is an analytic store model table. The predictedTarget parameter specifies that the variable P_good_badbad be used as the predicted target variable. The seed parameter specifies the seed to use for pseudorandom number generation. The preset parameter specifies that the preset explanation method is the global regression method. The inputs parameter specifies that the variables age, amount, coapp, duration, foreign, and job be used as inputs. The nominals parameter specifies that the variables coapp, foreign, and job be used as nominal variables.

For example output from the action, see the SAS code examples.

Last updated: November 04, 2020