Autotune Action Set
Tuning the Hyperparameters of t-Distributed Stochastic Neighbor Embedding
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts (SAS Viya: Machine Learning Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
This example illustrates the use of the tuneTsne action to automatically tune the hyperparameters for t-distributed stochastic neighbor embedding. The following DATA step loads the iris data set from the Sashelp library into a data table named mycas.iris. These statements assume that the CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
data mycas.iris;
set sashelp.iris;
id=_n_;
run;
The following PROC CAS code uses the tuneTsne action to automatically tune the hyperparameters of a two-dimensional embedding of the Iris data. Note that the syntax of the trainOptions parameter here is the same as the syntax of the tSne action. For more information about the tSne action, see Chapter 40, t-Distributed Stochastic Neighbor Embedding Action Set.
proc cas noqueue;
action autotune.tuneTsne /
trainOptions = {
table = {name='iris'},
inputs = {"SepalLength", "SepalWidth", "PetalLength", "PetalWidth"},
nDimensions = 2,
perplexity = 5,
learningRate = 100,
maxIters = 500,
output = {casOut={name="tsne_out", replace="TRUE"},
copyvars={"id", "species"}}
},
tunerOptions = {
searchMethod = "GA",
popSize = 10,
logLevel = 3,
seed = 12345
}
/* Tuning Parameters
You do not need to specify any tuning parameters for the default
tuning process. If you want to make adjustments to the default
tuning process, uncomment the following block of code and change
any of the tuning parameters' attributes.
, tuningParameters = {
{name="perplexity", initValue=30, lb=5, ub=50, exclude=false},
{name="learningRate", initValue=1000, lb=10, ub=2000, exclude=false},
{name="maxIters", initValue=300, lb=250, ub=5000, exclude=false}
}
*/
;
ods output TunerResults = TuneResults(keep=tSNEKLLoss);
ods output EvaluationHistory = EvalHistory;
ods output IterationHistory = IterHistory;
run;
quit;
The following optional code includes two DATA steps and two SGPLOT procedure steps that generate the following two plots from the tuneTsne action results:
history of all evaluations (the objective value versus the evaluation number, grouped by iteration)
iteration history (the best objective value and total tuning time versus the iteration number)
data _null_;
set TuneResults;
if _n_ = 1 then call symput('default', tSNEKLLoss);
else if _n_ = 2 then call symput('best', tSNEKLLoss);
run;
data EvalHistory;
set EvalHistory;
default = &default.;
best = &best.;
run;
proc sgplot data=EvalHistory;
title "Tune tSne with GA on Iris Data";
scatter x=Evaluation y=tSNEKLLoss / group=Iteration;
series x=Evaluation y=default /
curvelabel="default" lineattrs=(pattern=shortdash);
series x=Evaluation y=best /
curvelabel="best" lineattrs=(color=green pattern=shortdash);
run;
proc sgplot data=IterHistory;
title "Tune tSne with GA on Iris Data";
series x=Iteration y=Best_Obj;
series x=Iteration y=Time_Sec / y2axis;
run;
Output 7.18.1 shows the "Tuner Information" output table, which displays the values of parameters that the tuner used.
Output 7.18.1: Tuner Information Output
| Tuner Information | |
|---|---|
| Model Type | t-Distributed Stochastic Neighbor Embedding |
| Tuner Objective Function | Kullback-Leibler loss with pseudo-BIC penalty |
| Search Method | GA |
| Population Size | 10 |
| Maximum Iterations | 5 |
| Maximum Tuning Time in Seconds | 36000 |
| Validation Type | Validation Type |
| Log Level | 3 |
| Seed | 12345 |
| Number of Parallel Evaluations | 15 |
| Number of Workers per Subsession | 1 |
Output 7.18.2 shows the "Tuner Results" output table, which displays the default configuration (Evaluation 0) and up to 10 of the best configurations that the tuner found. For each configuration, the hyperparameter values and objective value are provided.
Output 7.18.2: Tuner Results Output
| Tuner Results Default and Best Configurations | |||||
|---|---|---|---|---|---|
| Evaluation | Learning Rate | Perplexity | Maximum Number of Iterations | Kullback-Leibler Loss | Evaluation Time in Seconds |
| 0 | 100.000000 | 5.000000 | 500 | 0.5664 | 1.95 |
| 63 | 230.954413 | 5.000000 | 2889 | 0.5172 | 5.05 |
| 64 | 128.292950 | 5.000000 | 2889 | 0.5176 | 5.03 |
| 51 | 13.871383 | 5.000000 | 2889 | 0.5222 | 5.11 |
| 42 | 10.000000 | 5.000000 | 5000 | 0.5233 | 8.66 |
| 28 | 10.000000 | 5.000000 | 2889 | 0.5262 | 5.52 |
| 55 | 10.000000 | 5.000000 | 2625 | 0.5268 | 4.78 |
| 66 | 13.871383 | 5.000000 | 5000 | 0.5304 | 8.99 |
| 67 | 1008.871383 | 5.000000 | 2889 | 0.5426 | 5.26 |
| 29 | 452.222222 | 5.000000 | 5000 | 0.5430 | 9.03 |
| 32 | 10.000000 | 5.000000 | 3668 | 0.5443 | 6.59 |
Output 7.18.3 shows the "Tuner Iteration History" output table, which displays the results of each iteration. For each iteration, the number of evaluations, the best objective value so far, and the tuning time in seconds are provided.
Output 7.18.3: Tuner Iteration History Output
| Tuner Iteration History | |||
|---|---|---|---|
| Iteration | Evaluations | Best Objective | Elapsed Time in Seconds |
| 0 | 1 | 0.57 | 1.95 |
| 1 | 17 | 0.55 | 21.42 |
| 2 | 31 | 0.53 | 30.45 |
| 3 | 44 | 0.52 | 39.11 |
| 4 | 56 | 0.52 | 47.72 |
| 5 | 68 | 0.52 | 56.71 |
Output 7.18.4 shows the "Tuner Evaluation History" output table, which displays all model configurations that the tuner evaluated. For each configuration, the hyperparameter values and objective value are provided.
Output 7.18.4: Tuner Evaluation History Output
| Tuner History All Evaluated Configurations | ||||||
|---|---|---|---|---|---|---|
| Evaluation | Iteration | Learning Rate | Perplexity | Maximum Number of Iterations | Kullback-Leibler Loss | Evaluation Time in Seconds |
| 0 | 0 | 100.000000 | 5.000000 | 500 | 0.5664 | 1.95 |
| 1 | 1 | 10.000000 | 20.000000 | 1306 | 0.8238 | 8.55 |
| 2 | 1 | 1778.888889 | 35.000000 | 4472 | 1.2677 | 9.26 |
| 3 | 1 | 1557.777778 | 50.000000 | 778 | 1.7517 | 8.55 |
| 4 | 1 | 1115.555556 | 40.000000 | 2361 | 1.4256 | 9.26 |
| 5 | 1 | 452.222222 | 5.000000 | 2889 | 0.5455 | 9.26 |
| 6 | 1 | 673.333333 | 25.000000 | 3944 | 0.9642 | 9.26 |
| 7 | 1 | 1336.666667 | 10.000000 | 250 | 3.7756 | 8.55 |
| 8 | 1 | 894.444444 | 30.000000 | 1833 | 1.1082 | 9.26 |
| 9 | 1 | 231.111111 | 15.000000 | 5000 | 0.6960 | 16.28 |
| 10 | 1 | 100.000000 | 5.000000 | 500 | 0.5664 | 6.66 |
| 11 | 1 | 1005.000000 | 27.500000 | 2625 | 1.0312 | 9.79 |
| 12 | 1 | 1005.000000 | 50.000000 | 2625 | 1.7517 | 10.35 |
| 13 | 1 | 1005.000000 | 5.000000 | 2625 | 0.5631 | 11.16 |
| 14 | 1 | 2000.000000 | 27.500000 | 2625 | 1.0351 | 11.81 |
| 15 | 1 | 10.000000 | 27.500000 | 2625 | 1.0319 | 15.57 |
| 16 | 1 | 1005.000000 | 27.500000 | 5000 | 1.0317 | 12.81 |
| 17 | 1 | 1005.000000 | 27.500000 | 250 | 3.8131 | 0.70 |
| 18 | 2 | 206.872204 | 16.287260 | 250 | 2.2255 | 1.17 |
| 19 | 2 | 180.776490 | 21.287260 | 1985 | 0.8590 | 4.18 |
| 20 | 2 | 1221.037009 | 31.846315 | 2807 | 1.1724 | 5.38 |
| 21 | 2 | 547.353161 | 5.000000 | 1736 | 0.5490 | 3.87 |
| 22 | 2 | 298.056529 | 25.583292 | 1208 | 0.9838 | 3.00 |
| 23 | 2 | 78.302726 | 11.544534 | 2899 | 0.6281 | 5.55 |
| 24 | 2 | 741.636059 | 26.544534 | 2563 | 1.0019 | 4.96 |
| 25 | 2 | 18.064682 | 9.952279 | 250 | 1.8700 | 1.02 |
| 26 | 2 | 591.398015 | 22.141791 | 3452 | 0.8780 | 6.39 |
| 27 | 2 | 1447.222222 | 5.000000 | 2889 | 0.5582 | 6.66 |
| 28 | 2 | 10.000000 | 5.000000 | 2889 | 0.5262 | 5.52 |
| 29 | 2 | 452.222222 | 5.000000 | 5000 | 0.5430 | 9.03 |
| 30 | 2 | 452.222222 | 5.000000 | 514 | 0.5788 | 1.55 |
| 31 | 2 | 452.222222 | 27.500000 | 2889 | 1.0334 | 5.65 |
| 32 | 3 | 10.000000 | 5.000000 | 3668 | 0.5443 | 6.59 |
| 33 | 3 | 94.550541 | 13.089300 | 2754 | 0.6594 | 4.86 |
| 34 | 3 | 916.891303 | 21.225823 | 2839 | 0.8560 | 5.13 |
| 35 | 3 | 386.986747 | 20.583570 | 2625 | 0.8396 | 4.94 |
| 36 | 3 | 526.162540 | 14.106968 | 3188 | 0.6851 | 6.08 |
| 37 | 3 | 771.375576 | 5.962846 | 1181 | 0.5565 | 2.49 |
| 38 | 3 | 302.325141 | 8.418810 | 2344 | 0.5546 | 4.31 |
| 39 | 3 | 120.761566 | 19.088880 | 2383 | 0.7844 | 4.42 |
| 40 | 3 | 238.041605 | 23.384913 | 1606 | 0.9116 | 3.20 |
| 41 | 3 | 1005.000000 | 5.000000 | 2889 | 0.5627 | 5.30 |
| 42 | 3 | 10.000000 | 5.000000 | 5000 | 0.5233 | 8.66 |
| 43 | 3 | 10.000000 | 5.000000 | 514 | 0.6192 | 1.39 |
| 44 | 3 | 10.000000 | 27.500000 | 2889 | 1.0319 | 5.36 |
| 45 | 4 | 10.000000 | 10.247194 | 3210 | 0.6049 | 5.48 |
| 46 | 4 | 422.182900 | 7.791231 | 2047 | 0.5746 | 3.54 |
| 47 | 4 | 227.822689 | 10.093524 | 2491 | 0.5925 | 4.21 |
| 48 | 4 | 398.054854 | 5.739073 | 4320 | 0.5519 | 7.47 |
| 49 | 4 | 10.000000 | 5.156050 | 2612 | 0.5527 | 4.77 |
| 50 | 4 | 272.120845 | 5.000000 | 2889 | 0.5636 | 5.03 |
| 51 | 4 | 13.871383 | 5.000000 | 2889 | 0.5222 | 5.11 |
| 52 | 4 | 68.744590 | 12.932100 | 2907 | 0.6265 | 5.12 |
| 53 | 4 | 83.017986 | 11.985933 | 2772 | 0.6258 | 4.62 |
| 54 | 4 | 1005.000000 | 5.000000 | 5000 | 0.5607 | 8.57 |
| 55 | 4 | 10.000000 | 5.000000 | 2625 | 0.5268 | 4.78 |
| 56 | 4 | 10.000000 | 27.500000 | 5000 | 1.0402 | 8.61 |
| 57 | 5 | 231.916280 | 5.710450 | 2369 | 0.5683 | 4.26 |
| 58 | 5 | 257.135500 | 5.470684 | 3800 | 0.5527 | 7.17 |
| 59 | 5 | 11.039766 | 5.000000 | 2889 | 0.5496 | 5.08 |
| 60 | 5 | 27.402715 | 5.000000 | 2889 | 0.5450 | 5.26 |
| 61 | 5 | 10.000000 | 5.048911 | 2636 | 0.5464 | 4.77 |
| 62 | 5 | 10.000000 | 6.109834 | 2957 | 0.5800 | 5.41 |
| 63 | 5 | 230.954413 | 5.000000 | 2889 | 0.5172 | 5.05 |
| 64 | 5 | 128.292950 | 5.000000 | 2889 | 0.5176 | 5.03 |
| 65 | 5 | 13.871383 | 5.000000 | 514 | 0.5865 | 1.34 |
| 66 | 5 | 13.871383 | 5.000000 | 5000 | 0.5304 | 8.99 |
| 67 | 5 | 1008.871383 | 5.000000 | 2889 | 0.5426 | 5.26 |
| 68 | 5 | 13.871383 | 27.500000 | 2889 | 1.0372 | 5.29 |
Output 7.18.5 shows the "Best Configuration" output table, which displays the values of hyperparameters and the objective value for the best configuration that the tuner found.
Output 7.18.5: Best Configuration Output
| Best Configuration | |
|---|---|
| Evaluation | 63 |
| Perplexity | 5 |
| Learning Rate | 230.954413 |
| Maximum Number of Iterations | 2889 |
| Kullback-Leibler loss with pseudo-BIC pe | 0.52 |
Output 7.18.6 shows the "Tuner Summary" output table, which displays statistics about the tuning process.
Output 7.18.6: Tuner Summary Output
| Tuner Summary | |
|---|---|
| Initial Configuration Objective Value | 0.5664 |
| Best Configuration Objective Value | 0.5172 |
| Worst Configuration Objective Value | 3.8131 |
| Initial Configuration Evaluation Time in Seconds | 1.9486 |
| Best Configuration Evaluation Time in Seconds | 5.0482 |
| Number of Improved Configurations | 6 |
| Number of Evaluated Configurations | 68 |
| Total Tuning Time in Seconds | 63.9364 |
| Parallel Tuning Speedup | 5.4529 |
Output 7.18.7 shows the "Tuner Task Timing" output table, which displays timing information about the different tasks that were performed during the tuning process.
Output 7.18.7: Tuner Task Timing Output
| Tuner Task Timing | ||
|---|---|---|
| Task | Seconds | Percent |
| Model Training | 338.70 | 97.15 |
| Model Scoring | 0.00 | 0.00 |
| Total Objective Evaluations | 338.71 | 97.15 |
| Tuner | 9.93 | 2.85 |
| Total CPU Time | 348.64 | 100.00 |
Output 7.18.8 shows the "Output CAS Tables" output table, which displays a list of CAS tables that were created during the tuning process.
Output 7.18.8: Output CAS Tables
| Output CAS Tables | |||
|---|---|---|---|
| CAS Library | Name | Number of Rows | Number of Columns |
| YOUR_CAS_LIB | tsne_out | 150 | 4 |
Output 7.18.9 shows the "Hyperparameter Importance" output table, which displays the relative importance of each hyperparameter during the tuning process, normalized by the effect of the most influential hyperparameter (importance set to 1) and listed in order of decreasing effect.
Output 7.18.9: Hyperparameter Importance Output
| Hyperparameter Importance | |
|---|---|
| Hyperparameter | Relative Importance |
| perplexity | 1.0000 |
| maxIters | 0.9942 |
| learningRate | 0.6953 |
The first PROC SGPLOT step creates a scatter plot of the objective value (Kullback-Leibler loss in this case) evaluation history by iteration, which is shown in Output 7.18.10. The second PROC SGPLOT step creates a line plot of the best objective value by iteration and a line plot of the total tuning time by iteration, which are shown in Output 7.18.11.
Output 7.18.10: Tuner Evaluation History Plot

Output 7.18.11: Tuner Iteration History Plot

Tuning the Hyperparameters of t-Distributed Stochastic Neighbor Embedding
This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the iris data to the comma-separated-value (CSV) file iris.csv and then use the following code to load the CSV file into CAS:
s:loadtable{casLib="casuser", path="iris.csv"}
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
The following Lua code uses the tuneTsne action to automatically tune the hyperparameters of a two-dimensional embedding of the iris data table. The data and the parameters are the same as in the PROC CAS version of this example. Note that the syntax of the trainOptions parameter here is the same as the syntax of the tSne action. For more information about the tSne action, see Chapter 40, t-Distributed Stochastic Neighbor Embedding Action Set.
result = s:autotune_tuneTsne {
trainOptions = {
table = {name='iris'},
inputs = {"SepalLength", "SepalWidth", "PetalLength", "PetalWidth"},
nDimensions = 2,
perplexity = 5,
learningRate = 100,
maxIters = 500,
output = {casOut={name="tsne_out", replace="TRUE"},
copyvars={"id", "species"}}
},
tunerOptions = {
searchMethod = "GA",
popSize = 10,
logLevel = 3,
seed = 12345
}
--[[ Tuning Parameters
You do not need to specify any tuning parameters for the default
tuning process. If you want to make adjustments to the default
tuning process, uncomment the following block of code and change
any of the tuning parameters' attributes.
, tuningParameters = {
{name="perplexity", initValue=30, lb=5, ub=50, exclude=false},
{name="learningRate", initValue=1000, lb=10, ub=2000, exclude=false},
{name="maxIters", initValue=300, lb=250, ub=5000, exclude=false}
}
--]]
}
The following commands display the tables that are produced by this action call:
print(result.TunerInfo)
print(result.TunerResults)
print(result.IterationHistory)
print(result.EvaluationHistory)
print(result.BestConfiguration)
print(result.TunerSummary)
print(result.TunerTiming)
print(result.TunerCasOutputTables)
print(result.HyperparameterImportance)
For details about the results of this analysis, see the PROC CAS version of this example.
Tuning the Hyperparameters of t-Distributed Stochastic Neighbor Embedding
This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the iris data to the comma-separated-value (CSV) file iris.csv and then use the following code to load the CSV file into CAS:
s.upload_file('iris.csv')
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
The following Python code uses the tuneTsne action to automatically tune the hyperparameters of a two-dimensional embedding of the iris data table. The data and the parameters are the same as in the PROC CAS version of this example. Note that the syntax of the trainOptions parameter here is the same as the syntax of the tSne action. For more information about the tSne action, see Chapter 40, t-Distributed Stochastic Neighbor Embedding Action Set.
result = s.autotune.tuneTsne (
trainOptions = {
"table" : {"name":"iris"},
"inputs" : {"SepalLength", "SepalWidth", "PetalLength", "PetalWidth"},
"nDimensions" : 2,
"perplexity" : 5,
"learningRate" : 100,
"maxIters" : 500,
"output" : {"casOut":{"name":"tsne_out", "replace":"TRUE"},
"copyvars":{"id", "species"}}
},
tunerOptions = {
"searchMethod" : "GA",
"popSize" : 10,
"logLevel" : 3,
"seed" : 12345
}
# Tuning Parameters
#
# You do not need to specify any tuning parameters for the default
# tuning process. If you want to make adjustments to the default
# tuning process, uncomment the following block of code and change
# any of the tuning parameters' attributes.
#
# , tuningParameters = [
# {"name":"perplexity",
# "initValue":30, "lb":5, "ub":50, "exclude":"false"},
# {"name":"learningRate",
# "initValue":1000, "lb":10, "ub":2000, "exclude":"false"},
# {"name":"maxIters",
# "initValue":300, "lb":250, "ub":5000, "exclude":"false"}
# ]
)
The following commands display the tables that are produced by this action call:
print(result.TunerInfo)
print(result.TunerResults)
print(result.IterationHistory)
print(result.EvaluationHistory)
print(result.BestConfiguration)
print(result.TunerSummary)
print(result.TunerTiming)
print(result.TunerCasOutputTables)
print(result.HyperparameterImportance)
For details about the results of this analysis, see the PROC CAS version of this example.
Tuning the Hyperparameters of t-Distributed Stochastic Neighbor Embedding
This example is not available for the R programming language.