RECENGINE Procedure

Example 28.4 Tuning Hyperparameters of a Bayesian Personalized Ranking Model

This example shows how to use the AUTOTUNE statement in the RECENGINE procedure to tune a Bayesian personalized ranking 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 by PROC RECENGINE) 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 usersCommunity. These statements assume that your libref is named mylib, but you can substitute any appropriately named libref.

   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 with the AUTOTUNE statement to tune a Bayesian personalized ranking model on the usersCommunity data:

proc recengine
   data=mylib.userscommunity
   method=bpr
   outmodel=mylib.bprmodel;
   input userid itemid / level=nominal;
   input issolvedtopic / level=interval;
   userid userid;
   itemid itemid;
   autotune
      /* Tuning Parameters
      You do not need to specify any tuning parameters for the default
      tuning process. If you want to make adjustments to the default
      tuning process, uncomment the following block of code and change
      any of the tuning parameters' attributes.

      tuningparameters=(
         MAXITER          ( init=20    lb=10     ub=100   )
         MINIBATCHSIZE    ( init=10000 lb=400    ub=40000 )
         NFACTORS         ( init=10    lb=5      ub=30    )
         LEARNSTEP        ( init=0.1   lb=0.001  ub=0.5   )
         REGULARIZATION   ( init=0.1   lb=0.001  ub=0.5   )
      )
      */
   ;
   ods select BestConfiguration; /* Remove to see all results tables */
run;

These statements produce the table shown in Output 28.4.1. The table displays the evaluation number, the values of the tuning parameters, and the error metric value for the best Bayesian personalized ranking model that the tuner found. Note that the ODS SELECT statement limits the displayed results to a single table. You can remove this statement to see all results tables. For the full list of ODS tables that PROC RECENGINE produces, see Table 3.

Output 28.4.1: Best Configuration Table

Best Configuration
Evaluation34
Maximum Number of Iterations60
Number of Factors27
Minibatch Size40000
Learning Step Size0.22277778
Regularization0.33366667
Mean Average Precision0.8943986667


Last updated: September 23, 2026