Graph-Based Semisupervised Learning Action Set

Home Mortgage 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 shows how to use the labelSpread action to predict the target variables for the unlabeled data between observations in a labeled data table and an unlabeled data table. In this case, the data are from the hmeq data set, which contains observations for mortgage applicants. This example selects 3,000 applicants for the unlabeled data table and 200 applicants for the labeled data table. The labelSpread action returns the predicted labels for applicants in the unlabeled data table and the labeled data table by combining the information from the unlabeled data and labeled data. The algorithm propagates the labels from labeled data to unlabeled data according to the similarity measure in an iterative algorithm. The analysis uses eight variables: bad, loan, mortdue, value, yoj, derog, clage, and debitinc. The remaining variables in the data table are not used. Because the labelSpread action relies on the pairwise distances as a similarity measure between two observations, any observations in the unlabeled and labeled data tables that contain missing data are ignored.

You can load the Unlabel and Label data sets into your CAS session by using the following DATA steps. These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

cas mysess;
libname mycas sasioca sessref=mysess;

data hmeq;
set sampsio.hmeq;
if cmiss(of _all_) then delete;
run;
data mycas.unlabel(drop=bad);
    set hmeq(obs=3000);
    id =_N_;
run;

data mycas.label;
    set hmeq(obs=200);
run;


The following statements use the labelSpread action to predict the labels for the Unlabel data table from the hmeq data. In this example, the value of the gamma parameter is 1,000.


proc cas;
 loadactionset "tkssl";
 action tkssl.labelSpread /
table={name="unlabel"},
labeledTable="label",
 inputs={"loan", "mortdue", "value", "yoj", "derog",
               "clage", "debtinc"},
 output=  {casout={name="out",   replace="TRUE"}, copyvars={"id","loan", "mortdue"}},

         target= "bad",
         gamma=1000,

          nominals={"bad"}            ;
          run;
quit;

The table parameter names the unlabeled data table, which contains the data without target variables. The labeledTable parameter names the labeled data table, which contains the data with target variables. The inputs parameter specifies the input variables to be used. The gamma parameter specifies 1,000 as the inverse of the variance for Gaussian kernels when you are computing the pairwise distance between data observations. The output parameter outputs the list of predicted labels for both the unlabeled data and the labeled data to the Out data table. The target parameter specifies the target variable name for the labeled data.

Output 20.1.1 shows the number of unlabeled observations, number of labeled observations, number of levels for target variable, gamma value, maximum number of iterations, and kernels used in the similarity measure.

Output 20.1.1: Model Information

Results from graphSemiSupLearn.labelSpread

Model Information
Labeled Observations Used200
Unlabeled Observations Used3000
Maximum Iterations3
Target Number of Levels2
Gamma1000
Kernel FunctionRBF


Output 20.1.2 shows the loss that the labelSpread computed on the basis of the input data and the prediction results.

Output 20.1.2: Loss

Loss
Value
52.057154648


The following statements sort the output of the labelSpread action by id and show the observations from 2000 to 2007:

data out2; set mycas.out; run;
proc sort data=out2; by id; run;
proc print data=out2 (firstobs=2000 obs=2007);
run;

Output 20.1.3 shows the output, which includes the values of the loan and mortdue variables, the predicted labels for the eight observations, and the indicator for the unlabeled or labeled data.

Output 20.1.3: Predicted Labels for CAS Output

ObsidLOANMORTDUEI_BAD_WARN_
20001800176006109300
20011801177001084700
20021802177006496400
20031803177009330200
20041804177005088600
20051805177006026000
20061806177003625310
200718071770010739500


Home Mortgage 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 hmeq data to the comma-separated-value (CSV) file hmeq.csv and then use the following code to load the CSV file into CAS:

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

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

This example shows how to use the labelSpread action to predict the target variables for the unlabeled data by combining the information in the observations in a labeled data table and an unlabeled data table. In this case, the data are from the hmeq data set, which contains observations for mortgage applicants. This example selects 3,000 applicants for the unlabeled data table and 200 applicants for the labeled data table. The labelSpread action returns the predicted labels for applicants in the unlabeled data table by combining the information from the unlabeled data and labeled data. The analysis uses eight variables: bad, loan, mortdue, value, yoj, derog, clage, and debitinc. The remaining variables in the data table are not used.

The following statements use the labelSpread action to predict the labels for the unlabeled data table from the hmeq data. In this example, the value of the gamma parameter is 1,000.

s:loadactionset{actionset="tkssl"}
s:labelSpread{table={name="unlabel"},
          labeledTable={name="label"},
          inputs={'loan','mortdue','value','yoj','debtinc','clage','derog'},
         gamma=1000
          output={casout={name="out", replace="TRUE"}},
          target= "bad",
          nominals={"bad"}

         ;

s:fetch{table={name="out"}}

The table parameter names the unlabeled data table, which contains the data without target variables. The labeledTable parameter names the labeled data table, which contains the data with target variables. The inputs parameter specifies the input variables to be used. The gamma parameter specifies 1,000 as the inverse of the variance for Gaussian kernels when you are computing the pairwise distance between data observations. The output parameter outputs the list of predicted labels for both the unlabeled data and the labeled data to the Out data table. The target parameter specifies the target variable name for the labeled data.

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

Home Mortgage 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 hmeq data to the comma-separated-value (CSV) file hmeq.csv and then use the following code to load the CSV file into CAS:

s.upload_file('hmeq.csv')

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

This example shows how to use the labelSpread action to predict the target variables for the unlabeled data by combining the information from observations in a labeled data table and an unlabeled data table. In this case, the data are from the hmeq data set, which contains observations for mortgage applicants. This example selects 3,000 applicants for the unlabeled data table and 200 applicants for the labeled data table. The labelSpread action returns the predicted labels for applicants in the unlabeled data table by combining the information from the unlabeled data and labeled data. The analysis uses eight variables: bad, loan, mortdue, value, yoj, derog, clage, and debitinc. The remaining variables in the data table are not used.

The following statements use the labelSpread action to predict the labels for the unlabeled data table from the hmeq data. In this example, the value of the gamma parameter is 1,000.

 s.loadactionset{actionset="tkssl"}
 s.labelSpread(output={"casOut":{"name":"out", "replace":True}},
           inputs={"loan","mortdue","value","yoj","debtinc","clage","derog"},
           target="bad",
           gamma=1000,
           labeledTable={ "name":"label"},
           table={ "name":"unlabel"}
           nominals={"bad"}
           )

 out=s.CASTable('out')
 pprint(out.fetch(to=20))

The table parameter names the unlabeled data table, which contains the data without target variables. The labeledTable parameter names the labeled data table, which contains the data with target variables. The inputs parameter specifies the input variables to be used. The gamma parameter specifies 1,000 as the inverse of the variance for Gaussian kernels when you are computing the pairwise distance between data observations. The output parameter outputs the list of predicted labels for both the unlabeled data and the labeled data to the Out data table. The target parameter specifies the target variable name for the labeled data.

Home Mortgage 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 hmeq data to the comma-separated-value (CSV) file hmeq.csv and then use the following code to load the CSV file into CAS:

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

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

This example shows how to use the labelSpread action to predict the target variables for the unlabeled data by combining the information from observations in a labeled data table and an unlabeled data table. In this case, the data are from the hmeq data set, which contains observations for mortgage applicants. This example selects 3,000 applicants for the unlabeled data table and 200 applicants for the labeled data table. The labelSpread action returns the predicted labels for applicants in the unlabeled data table by combining the information from the unlabeled data and labeled data. The analysis uses eight variables: bad, loan, mortdue, value, yoj, derog, clage, and debitinc. The remaining variables in the data table are not used.

The following statements use the labelSpread action to predict the labels for the unlabeled data table from the hmeq data. In this example, the value of the gamma parameter is 1,000.


 data <- read.csv("hmeq.csv", header = T)
 ds1 <- as.casTable(s,
                    data[1:3000,],
                    casOut =list(name = "unlabel",replace = TRUE))
 loadActionSet(s,'datastep')
 cas.dataStep.runCode(s,
                      code   = "data unlabel;
                                  set unlabel;

                                run;",
                      single = 'YES')

 ds2 <- as.casTable(s,
                    data[3001:3200,],
                    casOut =list(name = "label",replace = TRUE))
 cas.dataStep.runCode(s,
                      code   = "data label;
                                  set label;

                                run;",
                      single = 'YES')

 loadActionSet(s,'labelSpread')
 rs <- cas.tkssl.labelSpread(s,
 table      = list(name = "unlabel"),
 labeledTable      = list(name = "label"),
 inputs     = list("loan","mortdue","value","yoj","debtinc","clage","derog"),
 gamma         = 1000,
 output     = list(casout = list(name = "out",
 replace = TRUE)))

The table parameter names the unlabeled data table, which contains the data without target variables. The labeledTable parameter names the labeled data table, which contains the data with target variables. The inputs parameter specifies the input variables to be used. The gamma parameter specifies 1,000 as the inverse of the variance for Gaussian kernels when you are computing the pairwise distance between data observations. The output parameter outputs the list of predicted labels for both the unlabeled data and the labeled data to the Out data table. The target parameter specifies the target variable name for the labeled data.

Last updated: October 09, 2026