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
| Obs | Variable | Level | Bias | Factor1 | Factor2 | Factor3 | Factor4 | Factor5 | Factor6 | Factor7 | Factor8 | Factor9 | Factor10 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | _GLOBAL_ | 3.52986 | 0.00000 | 0.00000 | 0.00000 | 0.00000 | 0.00000 | 0.00000 | 0.00000 | 0.00000 | 0.00000 | 0.00000 | |
| 2 | userid | 1 | 0.08043 | 0.14034 | 0.36798 | -0.52760 | -0.31465 | 0.22486 | -0.28397 | -0.87780 | 0.24885 | 0.02000 | -0.14646 |
| 3 | userid | 2 | 0.17982 | 0.54746 | 0.00647 | -0.47194 | -0.39421 | -0.19759 | 0.51829 | -0.10209 | 0.01729 | 0.26124 | -0.12959 |
| 4 | userid | 3 | -0.73356 | -0.54006 | 0.01826 | 0.31498 | 0.11264 | 0.73452 | 0.31893 | -0.06499 | -0.63882 | -0.45544 | 0.18285 |
| 5 | userid | 4 | 0.80347 | 0.26031 | 0.04870 | -0.25062 | -0.01312 | -0.29526 | 0.53290 | -0.58693 | 0.00283 | 0.36615 | 0.40131 |
| 6 | userid | 5 | -0.65557 | 0.51211 | 0.07824 | -0.08614 | -0.01463 | 0.46066 | -0.30982 | -0.21790 | 0.37157 | -1.06146 | -0.29942 |
| 7 | userid | 6 | 0.10521 | 0.17515 | 0.18334 | -0.51516 | 0.53364 | -0.55709 | -0.16770 | -0.05254 | 0.39754 | 0.29666 | 0.23568 |
| 8 | userid | 7 | 0.43540 | 0.25194 | 0.07348 | -0.05654 | -0.02345 | -0.24364 | 0.14093 | -0.03300 | -0.46717 | 0.51100 | -0.19197 |
| 9 | userid | 8 | 0.26675 | 0.11208 | 0.57564 | 0.02860 | -0.77657 | -0.16036 | -0.41215 | -0.06069 | 0.76389 | -0.00608 | -0.11334 |
| 10 | userid | 9 | 0.74287 | 0.18856 | -0.10608 | 0.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
| Obs | userid | itemid | rating | P_rating |
|---|---|---|---|---|
| 1 | 196 | 242 | 3 | 4.09834 |
| 2 | 186 | 302 | 3 | 3.78284 |
| 3 | 22 | 377 | 1 | 1.42463 |
| 4 | 244 | 51 | 2 | 3.20907 |
| 5 | 166 | 346 | 1 | 2.58391 |
| 6 | 298 | 474 | 4 | 4.60470 |
| 7 | 115 | 265 | 2 | 3.43183 |
| 8 | 253 | 465 | 5 | 4.57718 |
| 9 | 305 | 451 | 3 | 2.96174 |
| 10 | 6 | 86 | 3 | 4.44866 |
| 11 | 62 | 257 | 2 | 3.08217 |
| 12 | 286 | 1014 | 5 | 3.08536 |
| 13 | 200 | 222 | 5 | 4.46180 |
| 14 | 210 | 40 | 3 | 3.30407 |
| 15 | 224 | 29 | 3 | 3.15151 |
| 16 | 303 | 785 | 3 | 3.03463 |
| 17 | 122 | 387 | 5 | 4.47396 |
| 18 | 194 | 274 | 2 | 2.57941 |
| 19 | 291 | 1042 | 4 | 3.47518 |
| 20 | 234 | 1184 | 2 | 1.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.