Graph-Based Semisupervised Learning Action Set
Example 11.1 Home Mortgage Data
Home Mortgage 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 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);
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"}},
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 11.1.1 shows the number of unlabeled observations, number of labeled observations, number of levels for target variable, gamma value, and maximum number of iterations.
Output 11.1.1: Model Information
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 loaded into CAS. 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.
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 loaded into CAS. 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 loaded into CAS. 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.