The FACTMAC Procedure

Example 6.1 Running PROC FACTMAC with the MovieLens Data Set

This example draws on data that are derived from companies that provide movies for online viewing. A company wants to offer its customers recommendations of movies that they might like. These recommendations are based on ratings that are provided by users. The MovieLens data set was developed by the GroupLens project at the University of Minnesota and is available at http://grouplens.org/datasets/movielens. This example uses the MovieLens 100K version.

There are four columns in the MovieLens 100K data set: user ID, item ID (each item is a movie), timestamp, and rating. This example predicts the rating for a specified user ID and an item ID. The data set is very sparse because most combinations of users and movies are not rated.

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. [3] The file that contains the ratings is u.data. Assuming the directory is /dept/app/doc/vb023/en/src/casml/factmac, the following DATA step loads the data table from the directory into your CAS session:

 proc casutil;
     load file="u.data"
     /*or other user-defined location*/
     casout="movlens"
     importoptions=(filetype="CSV" delimiter="TAB" getnames="FALSE"
                    vars=("userid" "itemid" "rating" "timestamp"));
 run;

The following statements show how to use PROC FACTMAC to predict movie ratings:

proc factmac data=mycas.movlens nfactors=10 learnstep=0.15
             maxiter=20  outmodel=mycas.factors;

   input userid itemid /level=nominal;
   target rating /level=interval;
   output out=mycas.out1 copyvars=(userid itemid rating);
run;

The following statements print the first 10 observations in the mycas.factors data table, which is specified in the OUTMODEL= option in the PROC FACTMAC statement. The output is shown in Figure 2.

proc print data=mycas.factors(obs=10);
run;

Figure 2: Bias Values and Factors

ObsVariableLevelBiasFactor1Factor2Factor3Factor4Factor5Factor6Factor7Factor8Factor9Factor10
1_GLOBAL_ 3.529860.000000.000000.000000.000000.000000.000000.000000.000000.000000.00000
2userid10.080430.140340.36798-0.52760-0.314650.22486-0.28397-0.877800.248850.02000-0.14646
3userid20.179820.547460.00647-0.47194-0.39421-0.197590.51829-0.102090.017290.26124-0.12959
4userid3-0.73356-0.540060.018260.314980.112640.734520.31893-0.06499-0.63882-0.455440.18285
5userid40.803470.260310.04870-0.25062-0.01312-0.295260.53290-0.586930.002830.366150.40131
6userid5-0.655570.512110.07824-0.08614-0.014630.46066-0.30982-0.217900.37157-1.06146-0.29942
7userid60.105210.175150.18334-0.515160.53364-0.55709-0.16770-0.052540.397540.296660.23568
8userid70.435400.251940.07348-0.05654-0.02345-0.243640.14093-0.03300-0.467170.51100-0.19197
9userid80.266750.112080.575640.02860-0.77657-0.16036-0.41215-0.060690.76389-0.00608-0.11334
10userid90.742870.18856-0.106080.22230-1.01906-0.18707-0.08458-0.02147-0.82411-0.21252-0.09411


The following statements print the predicted movie ratings for the first 20 observations, as shown in Figure 3.

proc print data=mycas.out1(obs=20);
run;

Figure 3: Predicted Movie Ratings

ObsuseriditemidratingP_rating
119624234.09834
218630233.78284
32237711.42463
42445123.20907
516634612.58391
629847444.60470
711526523.43183
825346554.57718
930545132.96174
1068634.44866
116225723.08217
12286101453.08536
1320022254.46180
142104033.30407
152242933.15151
1630378533.03463
1712238754.47396
1819427422.57941
19291104243.47518
20234118421.62934




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

Last updated: November 11, 2020