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 script l 1 penalization weight; REGL2=1.0 specifies the value of the script l 2 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

The MTLEARN Procedure

Model Information
Seed123
L1 Regularization0.5
L2 Regularization1
Tolerance0.01
Maximum Iterations10


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 Read10
Number of Observations Used10


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
VariableMeanStd Dev
X10.4867730.863056
X20.1984441.215561
X3-0.1498701.083567
Y14.0133099.723587
Y23.8566379.545267
Y34.9299538.636507


Figure 4 shows the iteration history of the objective function.

Figure 4: Iteration History

Iteration History
IterationObjective
Function
0381.53329458
1168.56137127
276.435700052
339.95948095
427.044926296
523.227784499
622.553144392
722.695112662
822.769024386
922.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

idX1X2X3P_Y1P_Y2P_Y3
00.912621.288761.568042.89562.66592.6911
30.29152-0.17617-0.175393.80393.74163.7899
60.426931.31982-0.02247-2.1305-2.2776-2.3144
91.56877-0.900520.3342920.217619.901620.1579
1-0.69684-1.487811.383060.20400.44110.4553
40.721480.47267-0.522694.98284.79284.8505
7-1.04654-0.19002-1.75929-9.6041-9.3888-9.5053
20.970062.40560-1.63855-1.9203-2.2583-2.3010
51.56378-1.04760-0.2987320.895220.575520.8414
80.155960.29972-0.366970.11760.06490.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_
X110.09069.863959.98828
X2-4.8786-4.91644-4.98455
X3-0.01650.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

idY1Y2Y3
001-1


Last updated: August 06, 2026