The MBANALYSIS Procedure
Example 14.1 Training a Model
Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.
This example trains the model by using data that are available in the sampsio.Assocs data set. This data set contains 1,000 transactions of 1,000 customers; each transaction contains information about the customer, time, and item or product. The customer (ID) variable is named Customer. The target variable is named Product, and the time variable is ignored. To perform association discovery, the input data table must have a separate observation for each product that is purchased by each customer. You must assign the ID role to one variable and the target model role to another variable when you create the data source. Only one variable is supported as the customer variable and only one variable is supported as the target variable.
You can load the sampsio.assocs data set into your CAS session by specifying your CAS engine libref in the first statement in the following DATA step. These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
data mycas.assocs;
set sampsio.assocs;
run;
The following DATA steps create two hierarchies, mycas.firstLevel and mycas.secondLevel:
data mycas.firstLevel;
length Item $20 Category $20;
Item='apples'; Category='Fruits'; output;
Item='artichok'; Category='Vegetables'; output;
Item='avocado'; Category='Fruits'; output;
Item='baguette'; Category='Bread'; output;
Item='bordeaux'; Category='Wine'; output;
Item='bourbon'; Category='Whisky'; output;
Item='chicken'; Category='Non-Veg'; output;
Item='coke'; Category='Cold-Drink'; output;
Item='corned_b'; Category='Non-Veg'; output;
Item='cracker'; Category='Vegetables'; output;
Item='ham'; Category='Non-Veg'; output;
Item='heineken'; Category='Beer'; output;
Item='hering'; Category='Non-Veg'; output;
Item='ice_crea'; Category='Cold-Drink'; output;
Item='olives'; Category='Vegetables'; output;
Item='peppers'; Category='Fruits'; output;
Item='sardines'; Category='Non-Veg'; output;
Item='soda'; Category='Cold-Drink'; output;
Item='steak'; Category='Non-Veg'; output;
Item='turkey'; Category='Non-Veg'; output;
run;
data mycas.secondLevel;
length Category $20 Dept $20;
Category='Fruits'; Dept='Breakfast'; output;
Category='Vegetables'; Dept='Breakfast'; output;
Category='Bread'; Dept='Breakfast'; output;
Category='Wine'; Dept='Drinks'; output;
Category='Whisky'; Dept='Drinks'; output;
Category='Non-Veg'; Dept='Breakfast'; output;
Category='Cold-Drink'; Dept='Drinks'; output;
Category='Beer'; Dept='Drinks'; output;
run;
The following statements run the association analysis on the mycas.assocs data table:
proc mbanalysis data=mycas.assocs items=10 support=1 separator="\*"
nLHS_range=(2,3) nRHS_range=(4,5) antecedentList=("Fruits")
consequentList=("Non-Veg");
output out=mycas.out outfreq=mycas.outfreq outrule=mycas.outrule;
customer Customer;
target product;
hierarchy data = mycas.firstLevel mycas.secondLevel;
savestate rstore=mycas.myStateArm;
run;
The DATA= option names the input data table to be analyzed. The ITEMS= option specifies the number of items in a rule. The SUPPORT= option specifies the minimum level of support for a rule. The SEPARATOR= option specifies separator character in the antecedent (left-hand side) or consequent (right-hand side) of a rule. The NLHS_RANGE= option specifies range of number of items in the left-hand side (LHS) of a rule. The NRHS_RANGE= option specifies range of number of items in the right-hand side (RHS) of a rule. The ANTECEDENTLIST= option specifies the regular expression strings to match in the antecedent of a rule. The CONSEQUENTLIST= option specifies the regular expression strings to match in the consequent of a rule. The OUTPUT statement specifies output tables to contain results of the MBANALYSIS procedure. The CUSTOMER statement requests that the Customer variable be used to group the target variable into baskets. The TARGET statement requests that the Product variable be used as the target variable. The HIERARCHY statement specifies the item’s hierarchies. The RSTORE= option in the SAVESTATE statement specifies the binary scoring file to be used for scoring.