MTLEARN Procedure
Getting Started: MTLEARN Procedure
Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.
This example shows how to use the MTLEARN procedure to obtain regression models from observations in a data table. This example assumes that the CAS engine libref "mylib" and the caslib that is associated with "mylib" have already been created.
The following DATA step creates the input data table, toyData, in your CAS session. This data table contains seven variables: id is the row ID variable; X1, X2, and X3 are the input variables; and Y1, Y2, and Y3 are the target variables.
data mylib.toydata;
input id X1 X2 X3 Y1 Y2 Y3;
cards;
0 0.912621 1.288759 1.568040 2.813182 2.792080 2.792080
1 -0.696839 -1.487805 1.383056 0.187085 0.559484 0.559484
2 0.970062 2.405601 -1.638553 -1.903736 -2.301208 -2.301208
3 0.291515 -0.176170 -0.175393 3.842113 3.799427 3.799427
4 0.721477 0.472668 -0.522688 5.171737 4.906125 .
5 1.563781 -1.04760 -0.298725 21.160617 20.762561 .
6 0.426927 1.319816 -0.022467 -2.231491 -2.361400 .
7 -1.046538 -0.190017 -1.75929 -9.438538 -9.388092 .
8 0.155960 0.299715 -0.366969 0.109865 -0.00258535 .
9 1.568768 -0.900524 0.334290 20.422254 19.799980 19.799980
;
run;
The following DATA step creates the input graph table, mylib.toyr, in your CAS session. This data table encodes the relationships between the targets. In this example, the targets Y2 and Y3 are connected, meaning that the regression weights for Y2 and Y3 are expected to be similar. This data table contains four variables: id is the row ID variable, and Y1, Y2, and Y3 are the target variables.
data mylib.toyr;
input id Y1 Y2 Y3;
cards;
0 0 1 -1
;
run;
The following statements run PROC MTLEARN and output the results to ODS tables:
proc mtlearn data = mylib.toydata
graphType = CUSTOM
regL1 = 0.5
regL2 = 1.0
maxIter = 10
tolerance = 1e-2
seed = 123
graphTable = mylib.toyr
modelOut = mylib.mtl_outW
graphOut = mylib.mtl_outR
;
input X1 X2 X3;
target Y1 Y2 Y3;
output out = mylib.mtl_out copyvars = (id X1 X2 X3);
savestate rstore = mylib.mtl_ast;
ods select ModelInfo NObs DescStats OptIterHistory;
run;
GRAPHTYPE=CUSTOM indicates the use of a custom graph table that is specified in the GRAPHTABLE= option; REGL1=0.5 specifies the value of the penalization weight; REGL2=1.0 specifies the value of the
penalization weight; MAXITER=10 specifies the maximum number of iterations; TOLERANCE=1E–2 specifies the optimization tolerance as a stopping criterion; SEED=123 specifies the seed to use for pseudorandom number generation; GRAPHTABLE=MYLIB.TOYR specifies the user-defined graph table; MODELOUT=MYLIB.MTL_OUTW writes the estimated multitask regression weights to the data table
mylib.mtl_outW; GRAPHOUT=MYLIB.MTL_OUTR writes the graph table to the data table mylib.mtl_outR. The INPUT statement specifies that the X1, X2, and X3 variables be used as inputs. The TARGET statement specifies that the Y1, Y2, and Y3 variables be used as targets. The OUTPUT statement writes the scored results to the data table mylib.mtl_out, and the COPYVARS= option copies the id, X1, X2, and X3 variables to the output. The SAVESTATE statement with the RSTORE= option stores the estimated model in the data table mylib.mtl_ast for future scoring.
Figure 1 shows the values of the parameters that are used in multitask learning.
Figure 1: Model Information
| Model Information | |
|---|---|
| Seed | 123 |
| L1 Regularization | 0.5 |
| L2 Regularization | 1 |
| Tolerance | 0.01 |
| Maximum Iterations | 10 |
Figure 2 shows the "Number of Observations" information. Note that missing values are not allowed in the input variables, and any row that has at least one nonmissing target is used in the optimization. Because all rows in the mylib.toyData data table have at least one target that is not missing, the number of observations read and the number of observations used are equal in this example.
Figure 2: Number of Observations
| Number of Observations Read | 10 |
|---|---|
| Number of Observations Used | 10 |
Figure 3 shows statistics for each interval variable in the INPUT and TARGET statements, including the mean and standard deviation.
Figure 3: Interval Variable Statistics
| Interval Variables | ||
|---|---|---|
| Variable | Mean | Std Dev |
| X1 | 0.486773 | 0.863056 |
| X2 | 0.198444 | 1.215561 |
| X3 | -0.149870 | 1.083567 |
| Y1 | 4.013309 | 9.723587 |
| Y2 | 3.856637 | 9.545267 |
| Y3 | 4.929953 | 8.636507 |
Figure 4 shows the iteration history of the objective function.
Figure 4: Iteration History
| Iteration History | |
|---|---|
| Iteration | Objective Function |
| 0 | 381.53329458 |
| 1 | 168.56137127 |
| 2 | 76.435700052 |
| 3 | 39.95948095 |
| 4 | 27.044926296 |
| 5 | 23.227784499 |
| 6 | 22.553144392 |
| 7 | 22.695112662 |
| 8 | 22.769024386 |
| 9 | 22.603979523 |
The following statements use the PRINT procedure to extract the first 10 observations from the output score table. The results are shown in Figure 5.
proc print noobs data=mylib.mtl_out(obs=10);
run;
Figure 5: Multitask Learning Score Table
| id | X1 | X2 | X3 | P_Y1 | P_Y2 | P_Y3 |
|---|---|---|---|---|---|---|
| 0 | 0.91262 | 1.28876 | 1.56804 | 2.8956 | 2.6659 | 2.6911 |
| 3 | 0.29152 | -0.17617 | -0.17539 | 3.8039 | 3.7416 | 3.7899 |
| 6 | 0.42693 | 1.31982 | -0.02247 | -2.1305 | -2.2776 | -2.3144 |
| 9 | 1.56877 | -0.90052 | 0.33429 | 20.2176 | 19.9016 | 20.1579 |
| 1 | -0.69684 | -1.48781 | 1.38306 | 0.2040 | 0.4411 | 0.4553 |
| 4 | 0.72148 | 0.47267 | -0.52269 | 4.9828 | 4.7928 | 4.8505 |
| 7 | -1.04654 | -0.19002 | -1.75929 | -9.6041 | -9.3888 | -9.5053 |
| 2 | 0.97006 | 2.40560 | -1.63855 | -1.9203 | -2.2583 | -2.3010 |
| 5 | 1.56378 | -1.04760 | -0.29873 | 20.8952 | 20.5755 | 20.8414 |
| 8 | 0.15596 | 0.29972 | -0.36697 | 0.1176 | 0.0649 | 0.0640 |
The following PROC PRINT statements display the estimated regression weights table, which is shown in Figure 6:
proc print noobs data=mylib.mtl_outW;
run;
Figure 6: Output Regression Weights Table
| Variable | _W_Y1_ | _W_Y2_ | _W_Y3_ |
|---|---|---|---|
| X1 | 10.0906 | 9.86395 | 9.98828 |
| X2 | -4.8786 | -4.91644 | -4.98455 |
| X3 | -0.0165 | 0.00000 | -0.00036 |
The following PROC PRINT statements display the graph table, which is shown in Figure 7.
proc print noobs data=mylib.mtl_outR;
run;
Figure 7: Output Graph Table
| id | Y1 | Y2 | Y3 |
|---|---|---|---|
| 0 | 0 | 1 | -1 |