Analytic Store Scoring Action Set
Example 1.2 Scoring the German Credit Benchmark Data
Scoring German Credit Benchmark Data
This section contains PROC CAS code.
Note: Input data must be in a CAS table that is accessible in your CAS session. This 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 3: Shared Concepts in SAS Visual Data Mining and Machine Learning 8.3: Procedures Guide. For more information about PROC CAS and programming in CASL, see Getting Started with CASL, SAS Cloud Analytic Services: CAS Procedure Programming Guide and Reference, and SAS Viya: System Programming Guide.
This example uses the dmagecr data set from the SAS sample library to illustrate how to score an input data table in SAS Viya. The dmagegr data set contains 1,000 observations and contains the variables age, amount, and so on. For an exhaustive listing of the contents of this data set, you can run the following statements:
proc contents data=sampsio.dmagecr; run;
This example assumes that the analytic store has been created and is visible by the session and that all the necessary input tables are visible so that they can be accessed.
The following DATA step loads the dmagecr data set into a CAS data table named dmycas.magecr and adds an id variable that will act as a record identifier for joining the input table to the output table. These statements assume that the CAS engine libref is named mycas, but you can substitute any appropriately named CAS engine libref.
data mycas.dmagecr;
set sampsio.dmagecr;
id=_n_;
run;
The following statements use the svmtrain subaction of the svm action set to produce an analytic store. The input table is dmagecr, and the input interval variables are checking, coapp, and depend, as seen in the var parameter. The target variable telephon is specified in the emtarget parameter. The state of the training is saved in a table named save, as seen in the savestate parameter.
proc cas;
action svm.svmtrain /
table={name='dmagecr'},
var={'checking', 'coapp', 'depends'},
emtarget={name='telephon', options={order='formatted', leveltype='nominal'}},
kernel=2,
degree=2,
id= {'id'},
savestate={name='save', replace=true};
run;
The following statements use the input table mycas.dmagecr and the analytic store in the table mycas.save to produce the output table mycas.dmagecr:
proc cas;
loadactionset "aStore";
action aStore.score /
table={name='dmagecr'},
out={name='dmagecrout'},
rstore={name='save'};
run;
quit;
The following statements print the contents of five observations from the output table dmagecrout:
proc print data=mycas.dmagecrout(where=(id <= 5)); run;
Output 1.2.1 shows the results, where you see that the id variable is not ordered. Because the scoring is done in CAS—a distributed scoring environment—it is expected that the output table might not be in the same order as the input table. You must do additional programming if you need to sort the output by the id variable.
Output 1.2.1: Scored Observations
Scoring German Credit Benchmark Data
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 loaded into CAS. 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 Lua code uses the analytic store in the table mycas.save to score the input data table mycas.dmagecr and produces the output table mycas.dmagecr. Only five observations are fetched from the table, which contains 1,000 observations.
s:loadactionset{actionset='astore'}
summ = s:score{
table={name='dmagecr'},
out={name='dmagecrout', replace=true},
rstore={name='save'}
}
ooo=s:fetch{table={name="dmagecrout", where="(id<=5)"}}
print(ooo)
Because the scoring is done in CAS—a distributed scoring environment—the output from the print function (not shown here) has no provisions for results that are ordered by the id variable. You must do additional programming if you need to sort the output by the id variable.
Scoring German Credit Benchmark Data
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 loaded into CAS. 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 Python code uses the analytic store in the table mycas.save to score the input data table mycas.dmagecr and produces the output table mycas.dmagecrout. Only five observations are fetched from the table, which contains 1,000 observations.
s.loadactionset('aStore')
s.score(
table='dmagecr',
out='dmagecrout',
rstore='save'
)
m=s.fetch(table={'name':'dmagecrout','where':'(id<=5)'})
print(m)
Because the scoring is done in CAS—a distributed scoring environment—the output from the print function (not shown here) has no provisions for results that are ordered by the id variable. You must do additional programming if you need to sort the output by the id variable.
Scoring German Credit Benchmark Data
The R code uses the analytic store in the table mycas.save to score the input data table mycas.dmagecr and produces the output table mycas.dmagecrout. Only five observations are fetched from the table, which contains 1,000 observations.
loadActionSet(s, "aStore")
cas.aStore.score(
s,
out = list(name = "dmagecrout", replace = TRUE),
rstore = "save",
table = "dmagecr"
)
output <- cas.table.fetch(s, table = list(name = "dmagecrout"), to=5)
print(output)