RECENGINE Procedure
Example 28.1 Recommending SAS Users Community Pages to SAS Users
This example shows how to use the RECENGINE procedure to train a matrix factorization with partially defined factors (MF-PDF) model on the usersCommunity data set (which is available here:
https://support.sas.com/documentation/onlinedoc/viya/examples.htm
). The data set consists of click events over a period of time on a peer-to-peer-support community website. Each web page (viewed as an item in the action) on the site belongs to a message board that includes a number of topics of specific interest. The same user might have viewed the same web page multiple times. Also, in this data set, it is indicated whether or not the questions within the topic have been resolved. For each click event, the user ID and item ID are recorded. The data set includes 40,000 click events (user feedback).
The following code includes the DATA step that generates the data table mylib.usersCommunity.
data mylib.usersCommunity;
input itemid boardid userid isSolvedTopic;
datalines;
38 4817 6313 0
15 7589 1355 1
46 9560 2926 1
16 11635 3985 1
38 13023 4163 0
... more lines ...
The following statements use PROC RECENGINE to train an MF-PDF model on the usersCommunity data:
proc recengine data=mylib.usersCommunity method=dtos outmodel=mylib.factors;
input userid itemid /level=nominal;
input isSolvedTopic/level=interval;
userid userid;
itemid itemid;
dtos nFactors=12 maxIter=20 regL2=0.1
feedbackConfidenceSlope=50 /*confidence=isSolvedTopic*/;
savestate rstore=mylib.astoreModel;
run;
Note: When the option CONFIDENCE=ISSOLVEDTOPIC is commented out, the confidence takes a constant value that is optimally determined by training data. When this option is not commented out, the confidence takes its value from the isSolvedTopic column of the usersCommunity table.
When the training is completed, PROC RECENGINE produces the mylib.factors table, which contains the factors and biases of both items and users.
The following code shows how to find the top five items for a sample user, whose user ID is 2572, by using the built-in analytic store scoring function.
First, you need to create the scoring data table that includes user ID 2572:
data mylib.user2572;
input userid;
datalines;
2572
;
run;
Next, you use the ASTORE procedure to score the binary-format model mylib.astoreModel for this user:
proc astore;
setoption nTopRecoms 5;
score data=mylib.user2572 rstore=mylib.astoreModel out=mylib.rankedItemsDtos;
run;
quit;
The following statements print the top five recommended items for user 2572. The output is shown in Output 28.1.1.
proc print data=mylib.rankedItemsDtos;
run;
Output 28.1.1: Top Five Items for User 2572
| Obs | userid | _RECOMMENDED_itemid | _SCORE | _RANK |
|---|---|---|---|---|
| 1 | 2572 | 16 | 0.71173 | 1 |
| 2 | 2572 | 15 | 0.34203 | 2 |
| 3 | 2572 | 38 | 0.27307 | 3 |
| 4 | 2572 | 25 | 0.22279 | 4 |
| 5 | 2572 | 50 | 0.11351 | 5 |