Bayesian Optimization with Tall Arrays
This example shows how to use Bayesian optimization to select optimal parameters for training a kernel classifier by using the 'OptimizeHyperparameters' name-value argument. The sample data set airlinesmall.csv is a large data set that contains a tabular file of airline flight data. This example creates a tall table containing the data, and extracts class labels and predictor data from the tall table to run the optimization procedure.
When you perform calculations on tall arrays, MATLAB® uses either a parallel pool (default if you have Parallel Computing Toolbox™) or the local MATLAB session. If you want to run the example using the local MATLAB session when you have Parallel Computing Toolbox, you can change the global execution environment by using the mapreducer function.
Get Data into MATLAB
Create a datastore that references the folder location with the data. The data can be contained in a single file, a collection of files, or an entire folder. For folders that contain a collection of files, you can specify the entire folder location, or use the wildcard character, '*.csv', to include multiple files with the same file extension in the datastore. Select a subset of the variables to work with, and treat 'NA' values as missing data so that datastore replaces them with NaN values. Create a tall table that contains the data in the datastore.
ds = datastore('airlinesmall.csv'); ds.SelectedVariableNames = {'Month','DayofMonth','DayOfWeek',... 'DepTime','ArrDelay','Distance','DepDelay'}; ds.TreatAsMissing = 'NA'; tt = tall(ds) % Tall table
Starting parallel pool (parpool) using the 'Processes' profile ...
11-Nov-2024 08:00:40: Job Queued. Waiting for parallel pool job with ID 3 to start ...
Connected to parallel pool with 4 workers.
tt =
M×7 tall table
Month DayofMonth DayOfWeek DepTime ArrDelay Distance DepDelay
_____ __________ _________ _______ ________ ________ ________
10 21 3 642 8 308 12
10 26 1 1021 8 296 1
10 23 5 2055 21 480 20
10 23 5 1332 13 296 12
10 22 4 629 4 373 -1
10 28 3 1446 59 308 63
10 8 4 928 3 447 -2
10 10 6 859 11 954 -1
: : : : : : :
: : : : : : :
Prepare Class Labels and Predictor Data
Determine the flights that are late by 10 minutes or more by defining a logical variable that is true for a late flight. This variable contains the class labels. A preview of this variable includes the first few rows.
Y = tt.DepDelay > 10 % Class labelsY = M×1 tall logical array 1 0 1 1 0 1 0 0 : :
Create a tall array for the predictor data.
X = tt{:,1:end-1} % Predictor dataX =
M×6 tall double matrix
10 21 3 642 8 308
10 26 1 1021 8 296
10 23 5 2055 21 480
10 23 5 1332 13 296
10 22 4 629 4 373
10 28 3 1446 59 308
10 8 4 928 3 447
10 10 6 859 11 954
: : : : : :
: : : : : :
Remove rows in X and Y that contain missing data.
R = rmmissing([X Y]); % Data with missing entries removed
X = R(:,1:end-1);
Y = R(:,end); Perform Bayesian Optimization Using OptimizeHyperparameters
Optimize hyperparameters using the 'OptimizeHyperparameters' name-value argument.
Standardize the predictor variables.
Z = zscore(X);
Find the optimal values for the 'KernelScale' and 'Lambda' name-value arguments that minimize the loss on the holdout validation set. By default, the software selects and reserves 20% of the data as validation data, and trains the model using the rest of the data. You can change the holdout fraction by using the 'HyperparameterOptimizationOptions' name-value argument. For reproducibility, use the 'expected-improvement-plus' acquisition function and set the seeds of the random number generators using rng and tallrng. The results can vary depending on the number of workers and the execution environment for the tall arrays. For details, see Control Where Your Code Runs.
rng('default') tallrng('default') Mdl = fitckernel(Z,Y,'Verbose',0,'OptimizeHyperparameters', ... {'KernelScale','Lambda'},'HyperparameterOptimizationOptions', ... struct('AcquisitionFunctionName','expected-improvement-plus'))
Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 2: Completed in 7.2 sec - Pass 2 of 2: Completed in 2.5 sec Evaluation completed in 11 sec Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 1.9 sec Evaluation completed in 2.1 sec |=====================================================================================================| | Iter | Eval | Objective | Objective | BestSoFar | BestSoFar | KernelScale | Lambda | | | result | | runtime | (observed) | (estim.) | | | |=====================================================================================================| | 1 | Best | 0.19672 | 88.714 | 0.19672 | 0.19672 | 1.2297 | 0.0080902 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.86 sec Evaluation completed in 1.1 sec | 2 | Accept | 0.19672 | 36.205 | 0.19672 | 0.19672 | 0.039643 | 2.5756e-05 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.86 sec Evaluation completed in 1 sec | 3 | Accept | 0.19672 | 34.436 | 0.19672 | 0.19672 | 0.02562 | 1.2555e-08 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.71 sec Evaluation completed in 0.86 sec | 4 | Accept | 0.19672 | 28.46 | 0.19672 | 0.19672 | 92.644 | 1.2056e-07 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.95 sec Evaluation completed in 1.1 sec | 5 | Best | 0.11469 | 51.09 | 0.11469 | 0.12698 | 11.173 | 0.00024836 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.87 sec Evaluation completed in 1.1 sec | 6 | Best | 0.11365 | 46.935 | 0.11365 | 0.11373 | 10.609 | 0.00025761 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 1.3 sec Evaluation completed in 1.7 sec | 7 | Accept | 0.19672 | 38.05 | 0.11365 | 0.11373 | 0.0059498 | 0.00043861 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.96 sec Evaluation completed in 1.2 sec | 8 | Accept | 0.12122 | 67.149 | 0.11365 | 0.11371 | 11.44 | 0.00045722 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 1.4 sec Evaluation completed in 1.7 sec | 9 | Best | 0.10417 | 34.858 | 0.10417 | 0.10417 | 8.0424 | 6.7998e-05 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.85 sec Evaluation completed in 1 sec | 10 | Accept | 0.10433 | 35.041 | 0.10417 | 0.10417 | 9.6694 | 1.4948e-05 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.9 sec Evaluation completed in 1.1 sec | 11 | Best | 0.10409 | 32.068 | 0.10409 | 0.10411 | 6.2099 | 6.1093e-06 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.91 sec Evaluation completed in 1.1 sec | 12 | Best | 0.10383 | 32.241 | 0.10383 | 0.10404 | 5.6767 | 7.6134e-08 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 1.2 sec Evaluation completed in 1.4 sec | 13 | Accept | 0.10408 | 30.503 | 0.10383 | 0.10365 | 8.1769 | 8.5993e-09 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.8 sec Evaluation completed in 1 sec | 14 | Accept | 0.10404 | 31.542 | 0.10383 | 0.10361 | 7.6191 | 6.4079e-07 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.88 sec Evaluation completed in 1 sec | 15 | Best | 0.10351 | 29.2 | 0.10351 | 0.10362 | 4.2987 | 9.2645e-08 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.91 sec Evaluation completed in 1.2 sec | 16 | Accept | 0.10404 | 35.797 | 0.10351 | 0.10362 | 4.8747 | 1.7838e-08 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.79 sec Evaluation completed in 0.99 sec | 17 | Accept | 0.10657 | 56.418 | 0.10351 | 0.10357 | 4.8239 | 0.00016344 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.85 sec Evaluation completed in 1 sec | 18 | Best | 0.10299 | 28.704 | 0.10299 | 0.10358 | 3.5555 | 2.7165e-06 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.82 sec Evaluation completed in 1 sec | 19 | Accept | 0.10366 | 26.76 | 0.10299 | 0.10324 | 3.8035 | 1.3542e-06 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.81 sec Evaluation completed in 0.97 sec | 20 | Accept | 0.10337 | 27.165 | 0.10299 | 0.10323 | 3.806 | 1.8101e-06 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.84 sec Evaluation completed in 0.98 sec |=====================================================================================================| | Iter | Eval | Objective | Objective | BestSoFar | BestSoFar | KernelScale | Lambda | | | result | | runtime | (observed) | (estim.) | | | |=====================================================================================================| | 21 | Accept | 0.10345 | 29.083 | 0.10299 | 0.10322 | 3.3655 | 9.082e-09 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.81 sec Evaluation completed in 0.96 sec | 22 | Accept | 0.19672 | 34.622 | 0.10299 | 0.10322 | 999.62 | 1.2609e-06 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.78 sec Evaluation completed in 0.92 sec | 23 | Accept | 0.10315 | 26.257 | 0.10299 | 0.10306 | 3.6716 | 1.2445e-08 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.92 sec Evaluation completed in 1.1 sec | 24 | Accept | 0.19672 | 33.396 | 0.10299 | 0.10306 | 0.0010004 | 2.6214e-08 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.89 sec Evaluation completed in 1.1 sec | 25 | Accept | 0.19672 | 33.148 | 0.10299 | 0.10306 | 0.21865 | 0.0026529 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.86 sec Evaluation completed in 1.1 sec | 26 | Accept | 0.19672 | 32.696 | 0.10299 | 0.10306 | 299.92 | 0.0032109 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.84 sec Evaluation completed in 0.99 sec | 27 | Accept | 0.19672 | 33.701 | 0.10299 | 0.10306 | 0.002436 | 0.0040428 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 1.4 sec Evaluation completed in 1.7 sec | 28 | Accept | 0.19672 | 35.638 | 0.10299 | 0.10305 | 0.50559 | 3.3667e-08 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.9 sec Evaluation completed in 1.1 sec | 29 | Accept | 0.10354 | 31.452 | 0.10299 | 0.10313 | 3.7754 | 9.5626e-09 | Evaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.78 sec Evaluation completed in 0.96 sec | 30 | Accept | 0.10405 | 27.451 | 0.10299 | 0.10315 | 8.9864 | 2.3136e-07 |


__________________________________________________________
Optimization completed.
MaxObjectiveEvaluations of 30 reached.
Total function evaluations: 30
Total elapsed time: 1131.569 seconds
Total objective function evaluation time: 1108.785
Best observed feasible point:
KernelScale Lambda
___________ __________
3.5555 2.7165e-06
Observed objective function value = 0.10299
Estimated objective function value = 0.10332
Function evaluation time = 28.7039
Best estimated feasible point (according to models):
KernelScale Lambda
___________ __________
3.6716 1.2445e-08
Estimated objective function value = 0.10315
Estimated function evaluation time = 30.3551
Mdl =
ClassificationKernel
PredictorNames: {'x1' 'x2' 'x3' 'x4' 'x5' 'x6'}
ResponseName: 'Y'
ClassNames: [0 1]
Learner: 'svm'
NumExpansionDimensions: 256
KernelScale: 3.6716
Lambda: 1.2445e-08
BoxConstraint: 665.9442
Properties, Methods
Perform Bayesian Optimization by Using bayesopt
Alternatively, you can use the bayesopt function to find the optimal values of hyperparameters.
Split the data set into training and test sets. Specify a 1/3 holdout sample for the test set.
rng('default') % For reproducibility tallrng('default') % For reproducibility Partition = cvpartition(Y,'Holdout',1/3); trainingInds = training(Partition); % Indices for the training set testInds = test(Partition); % Indices for the test set
Extract training and testing data and standardize the predictor data.
Ytrain = Y(trainingInds); % Training class labels Xtrain = X(trainingInds,:); [Ztrain,mu,stddev] = zscore(Xtrain); % Standardized training data Ytest = Y(testInds); % Testing class labels Xtest = X(testInds,:); Ztest = (Xtest-mu)./stddev; % Standardized test data
Define the variables sigma and lambda to find the optimal values for the 'KernelScale' and 'Lambda' name-value arguments. Use optimizableVariable and specify a wide range for the variables because optimal values are unknown. Apply logarithmic transformation to the variables to search for the optimal values on a log scale.
N = gather(numel(Ytrain)); % Evaluate the length of the tall training array in memoryEvaluating tall expression using the Parallel Pool 'Processes': - Pass 1 of 1: Completed in 0.95 sec Evaluation completed in 1.1 sec
sigma = optimizableVariable('sigma',[1e-3,1e3],'Transform','log'); lambda = optimizableVariable('lambda',[(1e-3)/N, (1e3)/N],'Transform','log');
Create the objective function for Bayesian optimization. The objective function takes in a table that contains the variables sigma and lambda, and then computes the classification loss value for the binary Gaussian kernel classification model trained using the fitckernel function. Set 'Verbose',0 within fitckernel to suppress the iterative display of diagnostic information.
minfn = @(z)gather(loss(fitckernel(Ztrain,Ytrain, ... 'KernelScale',z.sigma,'Lambda',z.lambda,'Verbose',0), ... Ztest,Ytest));
Optimize the parameters [sigma,lambda] of the kernel classification model with respect to the classification loss by using bayesopt. By default, bayesopt displays iterative information about the optimization at the command line. For reproducibility, set the AcquisitionFunctionName option to 'expected-improvement-plus'. The default acquisition function depends on run time and, therefore, can give varying results.
results = bayesopt(minfn,[sigma,lambda], ... 'AcquisitionFunctionName','expected-improvement-plus')
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.1 sec
Evaluation completed in 1.2 sec
|=====================================================================================================|
| Iter | Eval | Objective | Objective | BestSoFar | BestSoFar | sigma | lambda |
| | result | | runtime | (observed) | (estim.) | | |
|=====================================================================================================|
| 1 | Best | 0.19651 | 57.988 | 0.19651 | 0.19651 | 1.2297 | 0.012135 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.2 sec
Evaluation completed in 1.3 sec
| 2 | Accept | 0.19651 | 79.098 | 0.19651 | 0.19651 | 0.039643 | 3.8633e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.2 sec
Evaluation completed in 1.4 sec
| 3 | Accept | 0.19651 | 56.052 | 0.19651 | 0.19651 | 0.02562 | 1.8832e-08 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.1 sec
Evaluation completed in 1.2 sec
| 4 | Accept | 0.19651 | 30.845 | 0.19651 | 0.19651 | 92.644 | 1.8084e-07 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1 sec
Evaluation completed in 1.2 sec
| 5 | Accept | 0.19651 | 29.632 | 0.19651 | 0.19651 | 978.95 | 0.00015066 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.2 sec
Evaluation completed in 1.3 sec
| 6 | Accept | 0.19651 | 59.789 | 0.19651 | 0.19651 | 0.0089609 | 0.0059189 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.5 sec
Evaluation completed in 1.6 sec
| 7 | Accept | 0.19651 | 65.017 | 0.19651 | 0.19651 | 0.0010015 | 1.4474e-08 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.1 sec
Evaluation completed in 1.2 sec
| 8 | Accept | 0.19651 | 49.186 | 0.19651 | 0.19651 | 0.27475 | 0.0044831 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.1 sec
Evaluation completed in 1.3 sec
| 9 | Accept | 0.19651 | 47.638 | 0.19651 | 0.19651 | 0.81326 | 1.0753e-07 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.2 sec
Evaluation completed in 1.3 sec
| 10 | Accept | 0.19651 | 63.384 | 0.19651 | 0.19651 | 0.0040507 | 0.00011333 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.92 sec
Evaluation completed in 1.1 sec
| 11 | Accept | 0.19651 | 26.133 | 0.19651 | 0.19651 | 980.38 | 1.362e-08 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.97 sec
Evaluation completed in 1.1 sec
| 12 | Accept | 0.19651 | 28.884 | 0.19651 | 0.19651 | 968.03 | 0.011653 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1 sec
Evaluation completed in 1.1 sec
| 13 | Accept | 0.19651 | 52.819 | 0.19651 | 0.19651 | 0.41617 | 1.6704e-07 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1 sec
Evaluation completed in 1.2 sec
| 14 | Best | 0.10059 | 23.028 | 0.10059 | 0.1006 | 2.9545 | 2.4479e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1 sec
Evaluation completed in 1.2 sec
| 15 | Accept | 0.10098 | 21.511 | 0.10059 | 0.1006 | 5.3367 | 2.7906e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.1 sec
Evaluation completed in 1.2 sec
| 16 | Accept | 0.10101 | 21.718 | 0.10059 | 0.1006 | 4.233 | 1.4951e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.1 sec
Evaluation completed in 1.2 sec
| 17 | Best | 0.10049 | 24.385 | 0.10049 | 0.10013 | 4.0225 | 2.3847e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.94 sec
Evaluation completed in 1.1 sec
| 18 | Accept | 0.10076 | 25.086 | 0.10049 | 0.10032 | 3.7144 | 1.9977e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.92 sec
Evaluation completed in 1.2 sec
| 19 | Accept | 0.10061 | 23.016 | 0.10049 | 0.10025 | 3.5125 | 4.2084e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1 sec
Evaluation completed in 1.1 sec
| 20 | Accept | 0.10056 | 22.464 | 0.10049 | 0.10029 | 3.7269 | 2.7754e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.89 sec
Evaluation completed in 1 sec
|=====================================================================================================|
| Iter | Eval | Objective | Objective | BestSoFar | BestSoFar | sigma | lambda |
| | result | | runtime | (observed) | (estim.) | | |
|=====================================================================================================|
| 21 | Accept | 0.10089 | 22.098 | 0.10049 | 0.10044 | 3.8681 | 2.9799e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.85 sec
Evaluation completed in 0.97 sec
| 22 | Accept | 0.10101 | 20.802 | 0.10049 | 0.10052 | 6.1914 | 8.6976e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.91 sec
Evaluation completed in 1.1 sec
| 23 | Accept | 0.10161 | 21.456 | 0.10049 | 0.10053 | 5.1566 | 5.2959e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.93 sec
Evaluation completed in 1.1 sec
| 24 | Accept | 0.1028 | 52.234 | 0.10049 | 0.10053 | 3.8952 | 0.00012578 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.2 sec
Evaluation completed in 1.4 sec
| 25 | Accept | 0.11158 | 46.388 | 0.10049 | 0.10053 | 12.25 | 0.00018879 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.1 sec
Evaluation completed in 1.2 sec
| 26 | Best | 0.10014 | 23.16 | 0.10014 | 0.10042 | 3.5501 | 2.292e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.97 sec
Evaluation completed in 1.1 sec
| 27 | Accept | 0.19651 | 63.413 | 0.10014 | 0.10042 | 0.0010185 | 1.3606e-06 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.2 sec
Evaluation completed in 1.5 sec
| 28 | Accept | 0.10103 | 25.725 | 0.10014 | 0.10053 | 3.4712 | 2.1357e-05 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.6 sec
Evaluation completed in 1.8 sec
| 29 | Accept | 0.19651 | 35.34 | 0.10014 | 0.10053 | 980.28 | 1.8241e-06 |
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 1.5 sec
Evaluation completed in 1.7 sec
| 30 | Accept | 0.19651 | 88.24 | 0.10014 | 0.10053 | 0.0010035 | 0.011867 |
__________________________________________________________
Optimization completed.
MaxObjectiveEvaluations of 30 reached.
Total function evaluations: 30
Total elapsed time: 1289.2296 seconds
Total objective function evaluation time: 1206.5294
Best observed feasible point:
sigma lambda
______ _________
3.5501 2.292e-05
Observed objective function value = 0.10014
Estimated objective function value = 0.10053
Function evaluation time = 23.1603
Best estimated feasible point (according to models):
sigma lambda
______ _________
3.5501 2.292e-05
Estimated objective function value = 0.10053
Estimated function evaluation time = 24.1295


results =
BayesianOptimization with properties:
ObjectiveFcn: @(z)gather(loss(fitckernel(Ztrain,Ytrain,'KernelScale',z.sigma,'Lambda',z.lambda,'Verbose',0),Ztest,Ytest))
VariableDescriptions: [1×2 optimizableVariable]
Options: [1×1 struct]
MinObjective: 0.1001
XAtMinObjective: [1×2 table]
MinEstimatedObjective: 0.1005
XAtMinEstimatedObjective: [1×2 table]
NumObjectiveEvaluations: 30
TotalElapsedTime: 1.2892e+03
NextPoint: [1×2 table]
XTrace: [30×2 table]
ObjectiveTrace: [30×1 double]
ConstraintsTrace: []
UserDataTrace: {30×1 cell}
ObjectiveEvaluationTimeTrace: [30×1 double]
IterationTimeTrace: [30×1 double]
ErrorTrace: [30×1 double]
FeasibilityTrace: [30×1 logical]
FeasibilityProbabilityTrace: [30×1 double]
IndexOfMinimumTrace: [30×1 double]
ObjectiveMinimumTrace: [30×1 double]
EstimatedObjectiveMinimumTrace: [30×1 double]
Return the best feasible point in the Bayesian model results by using the bestPoint function. Use the default criterion min-visited-upper-confidence-interval, which determines the best feasible point as the visited point that minimizes an upper confidence interval on the objective function value.
zbest = bestPoint(results)
zbest=1×2 table
sigma lambda
______ _________
3.5501 2.292e-05
The table zbest contains the optimal estimated values for the 'KernelScale' and 'Lambda' name-value arguments. You can specify these values when training a new optimized kernel classifier by using
Mdl = fitckernel(Ztrain,Ytrain,'KernelScale',zbest.sigma,'Lambda',zbest.lambda)
For tall arrays, the optimization procedure can take a long time. If the data set is too large to run the optimization procedure, you can try to optimize the parameters by using only partial data. Use the datasample function and specify 'Replace','false' to sample data without replacement.
See Also
bayesopt | bestPoint | cvpartition | datastore | fitckernel | gather | loss | optimizableVariable | tall