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 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 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 13.3.1, Output 13.3.2, and Output 13.3.3, respectively.
Output 13.3.1: Explainer Information
| Explainer Information | |||
|---|---|---|---|
| RowId | Description | cValue | Value |
| DATAGEN | Data Generation Method | None | . |
| DISTANCE | Distance Method | Uniform | . |
| EXPLAINER | Explainer Type | Regression | . |
| BINARYENCODING | Binary Encoding | None | . |
| STANDARDIZE | Standardize Parameter Estimates | None | . |
| INCLUDEMISSING | Include Missing as a Level | No | . |
| SEED | Seed | 1234 | 1234 |
Output 13.3.2: Explainer Parameter Estimates
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Variable | coapp | foreign | job | Estimate | QueryValue |
| Intercept | . | . | . | -0.055565382 | . |
| age | . | . | . | -0.000974072 | 31 |
| amount | . | . | . | 0.0000265989 | 3430 |
| coapp | 2 | . | . | 0.1311458094 | 0 |
| coapp | 3 | . | . | 0.002612758 | 0 |
| coapp | 1 | . | . | 0 | 1 |
| duration | . | . | . | 0.0030765563 | 24 |
| foreign | . | 2 | . | -0.001237269 | 0 |
| foreign | . | 1 | . | 0 | 1 |
| job | . | . | 1 | 0.074550958 | 0 |
| job | . | . | 2 | 0.0230962962 | 0 |
| job | . | . | 4 | -0.002683282 | 0 |
| job | . | . | 3 | 0 | 1 |
Output 13.3.3: Explainer Fidelity Information
| Explainer Fidelity | ||
|---|---|---|
| ModelPred | ExplainerPred | ExplainerRMSE |
| 0 | 0.0793099635 | 0.0829574625 |
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.