FACTMAC Procedure
Example 8.2 Tuning a Factorization Machine Model
This example illustrates how you can use the AUTOTUNE statement to automatically tune the hyperparameters of a factorization machine model from observations in the MovieLens data table. The data table is described in Example 8.1.
You can download the compressed archive file from the website at http://files.grouplens.org/datasets/movielens/ml-100k.zip and use any third-party unzip tool to extract all the files in the archive to the destination directory of your choice.[4] The file that contains the ratings is u.data.
The following statements load the data table from a directory accessible from the CAS client into your CAS session:
proc casutil;
load
file = "/my/data/u.data" /* full path to the data file */
casout = "movlens"
importoptions = (filetype="CSV" delimiter="TAB" getnames=false
vars=("userid" "itemid" "rating" "timestamp"));
run;
The following statements show how you can use the FACTMAC procedure with the AUTOTUNE statement to automatically tune the hyperparameters of a factorization machine model that is trained on the mylib.movlens data table:
proc factmac
data=mylib.movlens outmodel=mylib.factors;
input userid itemid /level=nominal;
target rating /level=interval;
output out=mylib.out1 copyvars=(userid itemid rating);
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=(
NFACTORS ( values=5 10 15 20 25 30 init=5 )
MAXITER ( values=10 20 30 40 50 60 70 80 90 100
110 120 130 140 150 160 170 180 190 200 init=30 )
LEARNSTEP ( values=1E-6 1E-5 1E-4 1E-3 1E-2 1E-1 1 init=1E-3 )
)
*/
;
/* Remove this line to see all results */
ods select BestConfiguration EvaluationHistoryPlot IterationHistoryPlot;
run;
The preceding statements produce the table and the plots shown in Output 8.2.1 through Output 8.2.3. The table in Output 8.2.1 displays the evaluation number, the values of the tuning parameters, and the error metric value for the best factorization machine model that the tuner found. Note that the ODS SELECT statement limits the displayed results to a single table and two plots. You can remove this statement to display all tables and plots. For the full list of ODS tables that PROC FACTMAC produces, see Table 4.
Output 8.2.1: Best Configuration Table
| Best Configuration | |
|---|---|
| Evaluation | 45 |
| Number of Factors | 5 |
| Maximum Number of Iterations | 50 |
| Learning Step Size | 1 |
| Root Average Square Error | 1.0016766983 |
Output 8.2.2 displays a scatter plot of all configurations that the tuner tried. The objective values are shown on the Y axis, and the evaluation numbers are shown on the X axis.
Output 8.2.2: Evaluation History Plot

The plot in Output 8.2.3 displays how the best found objective value and the elapsed time changed with each iteration of the tuner.
Output 8.2.3: Iteration History Plot

[4] 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.