Light Gradient Boosting Action Set
Abalone 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 lgbmTrain action to train a LightGBM model on observations in a data table. In this case, the data are derived from the population biology of the abalone Haliotis species, from the north coast and islands of Bass Strait in Tasmania. The abalone data set was developed by the GroupLens project at the University of Minnesota and is available at https://archive.ics.uci.edu/ml/datasets/abalone. This example uses the abalone data; 75% of the observations are put in the abalone_train data set, and 25% are put in abalone_test.
There are columns of physical measurements, such as Length, Diameter, Height, and Whole_weight in the abalone data set. This example predicts the age of abalone from their physical measurements.
You can download the data from the website at https://archive.ics.uci.edu/ml/datasets/abalone to the destination directory of your choice.[3] The files that contain the data are named abalone_train.csv and abalone_test.csv. The following DATA step loads the data table from the directory into your CAS session:
proc casutil;
load file="/dept/app/doc/viya/en/src/casactml/lightgradboost/abalone_train.csv"
casout="abalone_train";
load file="/dept/app/doc/viya/en/src/casactml/lightgradboost/abalone_test.csv"
casout="abalone_test";
run;
The following statements train a LightGBM model on the abalone data by using the lgbmTrain action:
proc cas;
loadactionset "lightGradBoost";
action lightGradBoost.lgbmTrain /
inputs={"Sex" "Length" "Diameter" "Height" "Whole_weight" "Shucked_weight"
"Viscera_weight" "Shell_weight"}
nominals={"Sex"}
output={casOut={name="scored_train",replace=true}}
saveState={name="savedstate",replace=true}
seed=12345.0
table={name="ABALONE_TRAIN"}
target="age"
validTable={name="ABALONE_TEST"};
run;
quit;
The table parameter names the input data table to be analyzed. The validTable parameter names the input validation data table to be analyzed. The casOut parameter names the output scoring results of the input data table. The inputs parameter specifies the input variables to be used. The nominals parameter specifies that the variable Sex is nominal. The target parameter specifies the target variable to be used. The seed parameter specifies that this seed be used to generate other seeds for the model; by default, it is unused in favor of the default values of other seeds. The saveState parameter saves the state of the action in an analytic store, savedstate, which is stored in a binary file that contains the action’s state after the action completes the training phase of data analysis.
Abalone 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 abalone data to the comma-separated-value (CSV) file abalone.csv and then use the following code to load the CSV file into CAS:
s:loadtable{casLib="casuser", path="abalone.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 train a LightGBM model on the abalone data by using the lgbmTrain action:
myFile1 = '/dept/app/doc/viya/en/src/casactml/lightgradboost/abalone_train.csv'
dmh = swat.CSVDataMsgHandler(myFile1, {nrecs=120})
s:addtable{table='abalone_train', datamsghandler=dmh, vars=dmh.vars, reclen=dmh.reclen}
myFile2 = '/dept/app/doc/viya/en/src/casactml/lightgradboost/abalone_test.csv'
dmh = swat.CSVDataMsgHandler(myFile2, {nrecs=120})
s:addtable{table='abalone_test', datamsghandler=dmh, vars=dmh.vars, reclen=dmh.reclen}
s:loadactionset{actionset="lightgradboost"}
s:lightGradBoost_lgbmtrain{inputs={"Sex","Length","Diameter","Height","Whole_weight",
"Shucked_weight","Viscera_weight","Shell_weight"},
nominals={"Sex"},output={casOut={name="scored_train",replace=true}},
saveState={name="savedstate",replace=true},
seed=12345.0,
table={name="ABALONE_TRAIN"},
target="age",
validTable={name="ABALONE_TEST"}}
s:fetch{table={name="scored_train"}}
The table parameter names the input data table to be analyzed. The validTable parameter names the input validation data table to be analyzed. The casOut parameter names the output scoring results of the input data table. The inputs parameter specifies the input variables to be used. The nominals parameter specifies that the variable Sex is nominal. The target parameter specifies the target variable to be used. The seed parameter specifies that this seed be used to generate other seeds for the model; by default, it is unused in favor of default values of other seeds. The saveState parameter saves the state of the action in an analytic store, savedstate, which is stored in a binary file that contains the action’s state after the action completes the training phase of data analysis.
Abalone 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 abalone data to the comma-separated-value (CSV) file abalone.csv and then use the following code to load the CSV file into CAS:
s.upload_file('abalone.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 train a LightGBM model on the abalone data by using the lgbmTrain action:
s.upload_file('abalone_train.csv')
s.upload_file('abalone_test.csv')
s.loadactionset(actionset="lightgradboost")
s.lightgradboost.lgbmTrain(inputs=['Sex','Length','Diameter','Height','Whole_weight',
'Shucked_weight','Viscera_weight','Shell_weight'],
nominals=['Sex'],output={'casout':{'name':'scored_train','replace':True}},
savestate={'name':'savedstate','replace':True},
seed=12345,table={'name':'ABALONE_TRAIN'},
target='age',
validtable={'name':'ABALONE_TEST'})
lgb_out =s.CASTable('scored_train')
The table parameter names the input data table to be analyzed. The validTable parameter names the input validation data table to be analyzed. The casOut parameter names the output scoring results of the input data table. The inputs parameter specifies the input variables to be used. The nominals parameter specifies that the variable Sex is nominal. The target parameter specifies the target variable to be used. The seed parameter specifies that this seed be used to generate other seeds of model; by default, it is unused in favor of default values of other seeds. The saveState parameter saves the state of the action in an analytic store, savedstate, which is stored in a binary file that contains the action’s state after the action completes the training phase of data analysis.
Abalone 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 abalone data to the comma-separated-value (CSV) file abalone.csv and then use the following code to load the CSV file into CAS:
m <- cas.read.csv(s, "abalone.csv", casOut=list(name="abalone"))
For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.
The following statements train a LightGBM model on the abalone data by using the lgbmTrain action:
m <- cas.read.csv(s, "abalone_train.csv", casOut=list(name="abalone_train"))
n <- cas.read.csv(s, "abalone_test.csv", casOut=list(name="abalone_test"))
loadActionSet(s,'lightgradboost')
rs <- cas.lightGradBoost.lgbmTrain(s,
inputs=list('Sex','Length','Diameter','Height','Whole_weight',
'Shucked_weight','Viscera_weight','Shell_weight'),
nominals=list('Sex'),
output=list(casOut=list(name='scored_train',replace='true')),
saveState=list(name='savedstate',replace='true'),
seed=12345.0,
table=list(name='ABALONE_TRAIN'),
target='age',
validTable=list(name='ABALONE_TEST'))
The table parameter names the input data table to be analyzed. The validTable parameter names the input validation data table to be analyzed. The casOut parameter names the output scoring results of the input data table. The inputs parameter specifies the input variables to be used. The nominals parameter specifies that the variable Sex is nominal. The target parameter specifies the target variable to be used. The seed parameter specifies that this seed be used to generate other seeds for the model; by default, it is unused in favor of the default values of other seeds. The saveState parameter saves the state of the action in an analytic store, savedstate, which is stored in a binary file that contains the action’s state after the action completes the training phase of data analysis.
[3] Disclaimer: SAS may reference other websites or content or resources for use at Customer’s sole discretion. SAS has no control over any websites or resources that are provided by companies or persons other than SAS. Customer acknowledges and agrees that SAS is not responsible for the availability or use of any such external sites or resources, and does not endorse any advertising, products, or other materials on or available from such websites or resources. Customer acknowledges and agrees that SAS is not liable for any loss or damage that may be incurred by Customer or its end users as a result of the availability or use of those external sites or resources, or as a result of any reliance placed by Customer or its end users on the completeness, accuracy, or existence of any advertising, products, or other materials on, or available from, such websites or resources.