Support Vector Machine Action Set

German Credit Benchmark Data

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 trains the model by using German Credit Benchmark data, which are available in the sampsio.dmagecr data set. This data set contains 1,000 observations, each of which contains an applicant’s information, including the applicant’s credit rating (GOOD or BAD). The binary target is named GOOD_BAD. Other input variables are Checking, Duration, History, and so on.

The contents of the sampsio.dmagecr data set are described at http://support.sas.com/documentation/cdl/en/emgs/59885/HTML/default/a001026918.htm.

You can load the sampsio.dmagecr data set into your CAS session by specifying your CAS engine libref in the second statement in the following DATA step:

data mycas.dmagecr;
   set sampsio.dmagecr;
run;

These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

The following statements run the SVM algorithm on the mycas.dmagecr data table by using the svmTrain action:

proc cas;
    action svm.svmtrain /
        table="dmagecr"
        nominals={"checking" "history" "purpose" "savings" "employed"
                   "marital" "coapp" "property" "other" "job" "housing"
                   "telephon" "foreign" "good_bad"}
        inputs={"duration" "amount" "installp" "resident" "existcr"
                "depends" "age" "checking" "history" "purpose" "savings"
                "employed" "marital" "coapp" "property" "other" "job"
                "housing" "telephon" "foreign"}
        target="good_bad";
run;
quit;

The table parameter names the input data table to be analyzed. The nominals parameter lists the nominal input variables and target variable to be used in the training. The inputs parameter lists all the input variables to be used in the training. The target parameter specifies the variable to be predicted.

The "Training Results" table in Output 38.1.1 shows that the inner product of weights is 11.6121718, the bias is 2.12967726, and the number of support vectors is 531, where 481 of those vectors are on the margin. The table also shows that the maximum decision function value (Maximum F) is 4.65134808 and the minimum decision function value (Minimum F) is –2.5713179.

Output 38.1.1: German Credit Data Training Results

Results from svm.svmTrain

Training Results
Inner Product of Weights11.6121718
Bias2.12967726
Total Slack (Constraint Violations)492.87883
Norm of Longest Vector4.17809329
Number of Support Vectors531
Number of Support Vectors on Margin481
Maximum F4.65134808
Minimum F-2.5713179
Number of Effects20
Columns in Data Matrix61


The "Misclassification Matrix" table in Output 38.1.2 shows that among the total of 1,000 observations, 700 observations are classified as good and 300 observations are classified as bad. The number of correctly predicted good observations is 626, and the number of correctly predicted bad observations is 158. Thus the accuracy is 78.4%, as indicated in the "Fit Statistics" table in Output 38.1.3.

Output 38.1.2: German Credit Misclassification Matrix

Misclassification Matrix
ObservedTraining Prediction
badgoodTotal
bad158142300
good74626700
Total2327681000


Output 38.1.3: German Credit Accuracy

Fit Statistics
StatisticTraining
Accuracy0.7840
Error0.2160
Sensitivity0.5267
Specificity0.8943


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 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 code loads the svm action set and then uses the svmTrain action to train an SVM model on the dmagecr data table:

s:loadactionset{actionset="svm"}
out = s:svmtrain{
    table = "dmagecr",
    nominals = {"checking","history","purpose","savings","employed","marital",
                "coapp","property","other","job","housing","telephon",
                "foreign","good_bad" },
    inputs = {"duration","amount","installp","resident","existcr","depends",
               "age","checking","history","purpose","savings","employed",
               "marital","coapp","property","other","job","housing","telephon",
               "foreign"},
    target = "good_bad"
}

The table parameter names the input data table to be analyzed. The nominals parameter lists the nominal input variables and target variable to be used in the training. The inputs parameter lists all the input variables to be used in the training. The target parameter specifies the variable to be predicted.

The following commands display the tables that are produced by this action call:

print(out.ModelInfo)
print(out.TrainingResult)
print(out.Misclassification)
print(out.FitStatistics)

For details about the results of this analysis, see the CASL version of this example.

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 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 code loads the svm action set and then uses the svmTrain action to train an SVM model on the dmagecr data table:


s.loadactionset("svm")
out=s.svmTrain(
     table = {"name":"dmagecr"},
     nominals = {"checking","history","purpose","savings","employed",
           "marital","coapp","property","other","job","housing",
                 "telephon","foreign","good_bad"},
     inputs = {"duration","amount","installp","resident","existcr",
               "depends","age", "checking","history","purpose","savings",
               "employed", "marital","coapp","property","other","job",
               "housing","telephon","foreign"},
     target = "good_bad"
)

The table parameter names the input data table to be analyzed. The nominals parameter lists the nominal input variables and target variable to be used in the training. The inputs parameter lists all the input variables to be used in the training. The target parameter specifies the variable to be predicted.

The following commands display the tables that are produced by this action call:

print(out.ModelInfo)
print(out.TrainingResult)
print(out.Misclassification)
print(out.FitStatistics)

For details about the results of this analysis, see the CASL version of this example.

German Credit Benchmark Data

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 code loads the svm action set and then uses the svmTrain action to train an SVM model on the dmagecr data table:

cas.read.csv(s,
     "dmagecr.csv",
     header = TRUE,
     casOut = list(name = "dmagecr", replace = TRUE))

loadActionSet(s, 'svm')

result<-cas.svm.svmTrain(s,
     table    = "dmagecr",
     nominals = list("checking", "history", "purpose", "savings", "employed",
                     "marital", "coapp", "property", "other", "job", "housing",
                     "telephon", "foreign", "good_bad"),
     inputs   = list("duration", "amount", "installp", "resident",
                     "existcr", "depends", "age", "checking",
                     "history", "purpose", "savings", "employed",
                     "marital", "coapp", "property", "other",
                     "job", "housing", "telephon", "foreign"),
     target   = "good_bad")

The table parameter names the input data table to be analyzed. The nominals parameter lists the nominal input variables and target variable to be used in the training. The inputs parameter lists all the input variables to be used in the training. The target parameter specifies the variable to be predicted.

The following command displays the tables that are produced by this action call:

print(result)

For details about the results of this analysis, see the CASL version of this example.

Last updated: August 04, 2026