Data Science Pilot Action Set
Feature Selection Using the selectFeatures 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.
The following DATA step creates the reference data table mycas.dmagecr 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.dmagecr;
set sampsio.dmagecr;
run;
The following statements run the selectFeatures action to select the top three features according to the symmetric uncertainty criterion. The action outputs a CAS output table, select_features_out, that contains the selected features.
proc cas;
loadactionset "dataSciencePilot";
dataSciencePilot.selectFeatures
/ table = "DMAGECR"
casOut = {name = "SELECT_FEATURES_OUT",
replace = True}
target = "good_bad"
selectionPolicy = {criterion = "SU" topk=3}
inputs = {{name = "age"},
{name = "amount"},
{name = "coapp"},
{name = "duration"},
{name = "foreign"},
{name = "job"}}
nominals = {"coapp", "foreign", "job"}
;
run;
fetch / table = "SELECT_FEATURES_OUT";
run;
quit;
The table parameter names the input reference data table. The casOut parameter names the output data table. The target parameter names the target variable. The selectionPolicy parameter specifies the feature selection policy. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.
The CAS output table is shown in Output 11.9.1.
Output 11.9.1: Feature Rank
| Selected Rows from Table SELECT_FEATURES_OUT | ||||
|---|---|---|---|---|
| _Index_ | Variable | Target | Rank | CritValue |
| 1 | amount | good_bad | 1 | 0.02515991 |
| 2 | duration | good_bad | 2 | 0.0238437128 |
| 3 | age | good_bad | 3 | 0.0127136068 |
Feature Selection Using the selectFeatures 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 and then use the following code to load the CSV file into CAS:
s:loadtable{casLib="casuser", path="dmagecr.csv"}
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
The following statements run the selectFeatures action to select the top three features according to the symmetric uncertainty criterion. The action outputs a CAS output table, select_features_out, that contains the selected features.
s:loadactionset{actionset="dataSciencePilot"}
s:dataSciencePilot_selectFeatures {
table = {name ="DMAGECR"},
casOut = {name = "SELECT_FEATURES_OUT",
replace = True},
target = "good_bad",
selectionPolicy = {criterion = "SU" topk=3},
inputs = {{name = "age"},
{name = "amount"},
{name = "coapp"},
{name = "duration"},
{name = "foreign"},
{name = "job"}},
nominals = {"coapp", "foreign", "job"}
}
s:fetch{table = {name = "SELECT_FEATURES_OUT"}}
The table parameter names the input reference data table. The casOut parameter names the output data table. The target parameter names the target variable. The selectionPolicy parameter specifies the feature selection policy. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.
For example output from the action, see the CASL code examples.
Feature Selection Using the selectFeatures 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 and then use the following code to load the CSV file into CAS:
m <- cas.read.csv(s, "dmagecr.csv", casOut=list(name="dmagecr"))
For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.
The following statements run the selectFeatures action to select the top three features according to the symmetric uncertainty criterion. The action outputs a CAS output table, select_features_out, that contains the selected features.
cas.loadActionSet(s,"dataSciencePilot")
cas.dataSciencePilot.selectFeatures(
s,
table = list(name ="DMAGECR"),
casOut = list(name = "SELECT_FEATURES_OUT",
replace = True),
target = "good_bad",
selectionPolicy = list(criterion = "SU", topk=3),
inputs = list("age",
"amount",
"coapp",
"duration",
"foreign",
"job"),
nominals = list("coapp",
"foreign",
"job")
)
cas.fetch(s, table = list(name = "SELECT_FEATURES_OUT"))
The table parameter names the input reference data table. The casOut parameter names the output data table. The target parameter names the target variable. The selectionPolicy parameter specifies the feature selection policy. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.
For example output from the action, see the CASL code examples.
Feature Selection Using the selectFeatures 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 and then use the following code to load the CSV file into CAS:
s.upload_file('dmagecr.csv')
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
The following statements run the selectFeatures action to select the top three features according to the symmetric uncertainty criterion. The action outputs a CAS output table, select_features_out, that contains the selected features.
s.loadactionset(actionset="dataSciencePilot")
s.dataSciencePilot.selectFeatures(
table = {"name" : "DMAGECR"},
target = "good_bad",
selectionPolicy = {"criterion":"SU", "topk":3},
inputs = ["age", "amount", "coapp", "duration", "foreign", "job"],
nominals = ["coapp", "foreign", "job"],
casOut = {"name" : "SELECT_FEATURES_OUT", "replace" : True}
)
s.fetch(table = {"name" : "SELECT_FEATURES_OUT"})
The table parameter names the input reference data table. The casOut parameter names the output data table. The target parameter names the target variable. The selectionPolicy parameter specifies the feature selection policy. The inputs parameter specifies that the age, amount, coapp, duration, foreign, and job variables be used as inputs. The nominals parameter specifies that the coapp, foreign, and job variables be used as nominal variables.
For example output from the action, see the CASL code examples.