FACTMAC Procedure
Getting Started: FACTMAC Procedure
Note: Input data must be in a table that is accessible in your session. You can refer to this table by using a two-level name. The first level is a libref, and the second level is the table name. For more information, see the section Using SAS Viya Workbench in Chapter 2, Shared Concepts.
This example shows how to use the FACTMAC procedure to learn a factorization machine model from observations in a SAS data table. This example uses the cars data set in the Sashelp library and illustrates the prediction of gas mileage of cars based on make and model. The analysis uses four variables: car make, car model, car type, and a variable named mpg_city, which measures the car’s fuel usage (in miles per gallon) for city driving. The remaining variables in the data table are not used.
You can load the cars data set into your SAS library in the following DATA step:
data mylib.cars;
set sashelp.cars;
run;
These statements assume that your SAS libref is named mylib, as in the section Using SAS Viya Workbench, but you can substitute any appropriately defined SAS libref.
The following statements run PROC FACTMAC and output the results to ODS tables:
proc factmac data=mylib.cars outmodel=mylib.factors maxiter=50
nfactors=5 learnstep=0.002;
input make model type /level=nominal;
target mpg_city /level=interval;
output out=mylib.score_out copyvars=(make model type mpg_city);
run;
proc print data=mylib.factors(obs=48);
run;
The NFACTORS= option requests that the model estimate five factors, the LEARNSTEP= option sets the optimization learning step to 0.002, the MAXITER= option requests that the optimization stop after 50 iterations, and the OUTMODEL= option requests that the model parameters be written to the mylib.factors data table. The INPUT statement specifies that the make, model, and type variables are to be used as nominal inputs. The TARGET statement specifies that mpg_city is the target variable to be predicted. The OUTPUT statement requests that the predictions be written to the data table mylib.score_out and that the make, model, type and mpg_city variables be copied from the mylib.cars data table to the mylib.score_out data table.
Figure 1 shows the global bias, the bias values for each level, and the list of the factors for the first 48 observations.
Figure 1: Bias Values and Factors
| Obs | Variable | Level | Bias | Factor1 | Factor2 | Factor3 | Factor4 | Factor5 |
|---|---|---|---|---|---|---|---|---|
| 1 | _GLOBAL_ | 20.0607 | 0.00000 | 0.00000 | 0.00000 | 0.00000 | 0.00000 | |
| 2 | Make | Acura | -0.6322 | -1.65189 | -2.34213 | 0.09553 | -4.06551 | 0.72563 |
| 3 | Make | Audi | -1.5871 | -0.23131 | 0.07828 | -0.35298 | -0.45827 | -0.20166 |
| 4 | Make | BMW | -1.3607 | 0.00777 | 0.05455 | -0.19466 | -0.07272 | 0.22275 |
| 5 | Make | Buick | -1.1719 | 2.96493 | 0.10815 | 3.14048 | -4.74293 | -0.28692 |
| 6 | Make | Cadillac | -3.5607 | -1.07033 | -0.99187 | 1.49699 | 0.58245 | 0.95669 |
| 7 | Make | Chevrolet | -0.3941 | 0.01216 | 0.00688 | 0.05321 | 0.00923 | -0.03507 |
| 8 | Make | Chrysler | -0.1941 | 0.56168 | -0.90681 | -0.77899 | -1.38498 | 1.48220 |
| 9 | Make | Dodge | -0.6761 | 0.53603 | 0.05044 | 0.03614 | 0.79867 | 0.46522 |
| 10 | Make | Ford | -0.7999 | -0.29532 | -0.16454 | 0.05845 | -0.27550 | 0.10528 |
| 11 | Make | GMC | -4.6857 | 1.03171 | -1.97310 | -0.91069 | -4.54418 | 2.00952 |
| 12 | Make | Honda | 7.7628 | 0.84902 | -0.54073 | -0.37149 | -0.87898 | -0.31334 |
| 13 | Make | Hummer | -10.0607 | -3.26652 | 2.06044 | -3.31811 | -1.32709 | -6.03068 |
| 14 | Make | Hyundai | 2.9393 | 0.30075 | 0.72757 | -0.78057 | 0.01371 | -0.13113 |
| 15 | Make | Infiniti | -2.8107 | -1.20270 | 2.23762 | 6.27459 | -3.97131 | 0.51608 |
| 16 | Make | Isuzu | -4.0607 | 6.31966 | -4.61052 | 2.32465 | -5.98882 | -2.33495 |
| 17 | Make | Jaguar | -2.5607 | -2.18175 | -1.36395 | -1.72034 | 2.88573 | 1.22202 |
| 18 | Make | Jeep | -2.7274 | 1.34136 | -4.71543 | 5.68740 | 0.25748 | -5.30474 |
| 19 | Make | Kia | 1.8483 | -5.30755 | 3.53864 | -4.75619 | 5.24446 | 2.55098 |
| 20 | Make | Land Rover | -6.0607 | -5.98657 | 1.73501 | 3.16050 | 0.16469 | -3.89031 |
| 21 | Make | Lexus | -2.6062 | -0.97068 | 1.83440 | 1.61661 | 0.77815 | 0.44383 |
| 22 | Make | Lincoln | -3.2830 | 1.32684 | 0.16185 | -0.68375 | -0.66196 | 1.17094 |
| 23 | Make | MINI | 6.4393 | -0.18316 | 1.88514 | -0.79716 | -2.62557 | 5.78783 |
| 24 | Make | Mazda | 1.3938 | -0.91171 | 1.95718 | -1.13241 | 0.70124 | 0.06483 |
| 25 | Make | Mercedes-Benz | -2.7146 | -0.16738 | 0.07799 | -0.20517 | -0.25945 | -0.08443 |
| 26 | Make | Mercury | -2.5052 | 0.93393 | 2.25607 | 0.17357 | 0.25786 | 1.27973 |
| 27 | Make | Mitsubishi | 0.8623 | -0.24432 | 0.35635 | 0.16703 | 0.32479 | -0.02810 |
| 28 | Make | Nissan | -0.3549 | -0.00132 | -0.02561 | 0.00751 | 0.00230 | -0.02652 |
| 29 | Make | Oldsmobile | 0.9393 | 0.21073 | 3.49856 | 5.92790 | -6.28979 | 2.92394 |
| 30 | Make | Pontiac | 0.4847 | -0.13061 | -1.70502 | -1.35086 | 1.14599 | 1.41535 |
| 31 | Make | Porsche | -2.6322 | -4.90259 | 4.56269 | 4.18555 | 0.66543 | -4.09505 |
| 32 | Make | Saab | 0.3678 | -0.18666 | 0.00714 | 0.16181 | 0.80439 | 0.61889 |
| 33 | Make | Saturn | 4.3143 | 1.90340 | -3.38020 | 3.73003 | 0.31785 | -0.34106 |
| 34 | Make | Scion | 11.4393 | 6.31009 | -6.22994 | 6.26170 | -1.74481 | 5.77012 |
| 35 | Make | Subaru | 0.2120 | 0.48494 | -0.36550 | -0.41698 | -0.49696 | 1.03908 |
| 36 | Make | Suzuki | 2.0643 | -1.72773 | 1.93579 | -0.77099 | -0.01766 | -1.50695 |
| 37 | Make | Toyota | 4.3678 | 0.29650 | -0.08574 | -0.13681 | 0.20477 | -0.54623 |
| 38 | Make | Volkswagen | 1.3393 | -0.05236 | 0.70879 | -1.49191 | -1.33924 | 0.19614 |
| 39 | Make | Volvo | -0.3107 | 0.91585 | -0.20479 | -0.64416 | -0.23166 | 0.74650 |
| 40 | Model | 3.5 RL 4dr | -2.0607 | 4.29008 | 6.32127 | 6.32609 | -6.32203 | -4.13052 |
| 41 | Model | 3.5 RL w/Navigation 4dr | -2.0607 | -2.53358 | 1.07033 | 6.32244 | 4.64185 | 0.88841 |
| 42 | Model | 300M 4dr | -2.0607 | 6.33258 | 6.32102 | -1.46105 | 6.32544 | 6.32405 |
| 43 | Model | 300M Special Edition 4dr | -2.0607 | -6.33347 | 4.20158 | -6.32730 | -0.68946 | 4.77917 |
| 44 | Model | 325Ci 2dr | -0.0607 | 0.75687 | -6.32171 | 6.32257 | -6.32459 | 6.32309 |
| 45 | Model | 325Ci convertible 2dr | -1.0607 | 6.33216 | -4.54598 | -0.49266 | 6.32496 | 6.32270 |
| 46 | Model | 325i 4dr | -0.0607 | -0.11359 | 4.98979 | 2.21139 | 5.50177 | 6.32416 |
| 47 | Model | 325xi 4dr | -1.0607 | -6.32539 | 1.49304 | 5.52169 | -6.13325 | 6.32568 |
| 48 | Model | 325xi Sport | -1.0607 | 6.32095 | -5.18676 | -0.45827 | -4.11622 | -3.12254 |