Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

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 pair 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 uses the tall table to run the optimization procedure.

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 'local' profile ...
connected to 6 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   
      :          :             :           :          :           :           :
      :          :             :           :          :           :           :

When you execute calculations on tall arrays, the default execution environment uses either the local MATLAB session or a local parallel pool (if you have Parallel Computing Toolbox™). You can use the mapreducer function to change the execution environment.

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 labels
Y =

  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 data
X =

  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 automatically using the 'OptimizeHyperparameters' name-value pair argument.

Standardize the predictor variables.

Z = zscore(X);

Find the optimal values for the 'KernelScale' and 'Lambda' name-value pair arguments that minimize five-fold cross-validation loss. For reproducibility, set the random seed for tall arrays and use the 'expected-improvement-plus' acquisition function.

rng('default') 
tallrng('default') % For reproducibility
Mdl = fitckernel(Z,Y,'Verbose',0,'OptimizeHyperparameters','auto',...
    'HyperparameterOptimizationOptions',struct('AcquisitionFunctionName','expected-improvement-plus'))
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 3: Completed in 9.1 sec
- Pass 2 of 3: Completed in 2 sec
- Pass 3 of 3: Completed in 2.9 sec
Evaluation completed in 17 sec

Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 2.4 sec
Evaluation completed in 2.7 sec
|=====================================================================================================|
| Iter | Eval   | Objective   | Objective   | BestSoFar   | BestSoFar   |  KernelScale |       Lambda |
|      | result |             | runtime     | (observed)  | (estim.)    |              |              |
|=====================================================================================================|
|    1 | Best   |     0.19684 |      142.25 |     0.19684 |     0.19684 |       1.2297 |    0.0080902 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|    2 | Accept |     0.19684 |      65.457 |     0.19684 |     0.19684 |     0.039643 |   2.5756e-05 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2.1 sec
|    3 | Accept |     0.19684 |       64.04 |     0.19684 |     0.19684 |      0.02562 |   1.2555e-08 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2 sec
|    4 | Accept |     0.19684 |      70.552 |     0.19684 |     0.19684 |       92.644 |   1.2056e-07 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2.1 sec
|    5 | Best   |     0.11465 |      110.25 |     0.11465 |     0.12696 |       11.173 |   0.00024836 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|    6 | Accept |     0.11482 |      120.81 |     0.11465 |     0.11469 |         11.6 |   0.00023941 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 2 sec
Evaluation completed in 2.2 sec
|    7 | Accept |     0.19684 |      69.935 |     0.11465 |     0.11464 |       25.242 |   0.00039858 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 1.9 sec
|    8 | Accept |     0.11612 |      112.26 |     0.11465 |     0.11428 |       7.8238 |   0.00051928 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|    9 | Best   |     0.10315 |      56.865 |     0.10315 |      0.1034 |       9.5079 |   1.6228e-08 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|   10 | Accept |     0.10361 |      53.425 |     0.10315 |     0.10339 |       9.8089 |    8.544e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2 sec
|   11 | Best   |     0.10269 |      53.639 |     0.10269 |     0.10271 |       8.7043 |   8.8678e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|   12 | Best   |     0.10264 |      57.069 |     0.10264 |     0.10262 |       5.0702 |   8.7446e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2 sec
|   13 | Accept |      0.1032 |      53.495 |     0.10264 |     0.10266 |       6.0627 |   1.0286e-08 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|   14 | Best   |     0.10247 |      52.683 |     0.10247 |      0.1025 |       3.6969 |    8.965e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2.1 sec
|   15 | Accept |     0.19684 |      75.223 |     0.10247 |      0.1025 |       993.29 |   8.8815e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 2 sec
Evaluation completed in 2.2 sec
|   16 | Accept |      0.1075 |      101.64 |     0.10247 |     0.10249 |       3.7513 |   0.00052631 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2.1 sec
|   17 | Best   |     0.10223 |      53.351 |     0.10223 |     0.10214 |       4.1228 |   8.7857e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|   18 | Accept |     0.19684 |      63.202 |     0.10223 |     0.10214 |    0.0010043 |    0.0052836 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2.1 sec
|   19 | Accept |     0.10301 |      52.799 |     0.10223 |     0.10251 |       4.1588 |   1.0109e-08 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2.1 sec
|   20 | Accept |     0.10291 |      54.454 |     0.10223 |     0.10251 |       7.3336 |   8.4868e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|=====================================================================================================|
| Iter | Eval   | Objective   | Objective   | BestSoFar   | BestSoFar   |  KernelScale |       Lambda |
|      | result |             | runtime     | (observed)  | (estim.)    |              |              |
|=====================================================================================================|
|   21 | Best   |     0.10194 |      49.856 |     0.10194 |     0.10225 |       3.8113 |   8.8671e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2.1 sec
|   22 | Best   |     0.10121 |      53.558 |     0.10121 |     0.10141 |       3.3132 |   8.9989e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|   23 | Accept |     0.10294 |      53.957 |     0.10121 |     0.10137 |       5.4153 |   1.1478e-05 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|   24 | Accept |     0.10297 |      49.455 |     0.10121 |     0.10136 |       4.5918 |   7.4273e-07 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|   25 | Accept |     0.10226 |      49.383 |     0.10121 |     0.10134 |       2.9349 |    8.293e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|   26 | Accept |     0.10188 |      53.047 |     0.10121 |     0.10128 |       3.2244 |    1.019e-07 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|   27 | Best   |     0.10096 |      52.627 |     0.10096 |     0.10121 |       3.2763 |   1.4374e-08 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.3 sec
Evaluation completed in 1.5 sec
|   28 | Accept |     0.19684 |      61.924 |     0.10096 |     0.10121 |    0.0048849 |    0.0039902 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.8 sec
Evaluation completed in 2 sec
|   29 | Accept |      0.1018 |      49.423 |     0.10096 |     0.10138 |       3.2511 |   8.7094e-09 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.7 sec
Evaluation completed in 1.9 sec
|   30 | Accept |     0.10164 |      49.933 |     0.10096 |     0.10143 |       3.2002 |   8.4371e-09 |

__________________________________________________________
Optimization completed.
MaxObjectiveEvaluations of 30 reached.
Total function evaluations: 30
Total elapsed time: 2031.7757 seconds.
Total objective function evaluation time: 2006.5588

Best observed feasible point:
    KernelScale      Lambda  
    ___________    __________

      3.2763       1.4374e-08

Observed objective function value = 0.10096
Estimated objective function value = 0.10143
Function evaluation time = 52.6271

Best estimated feasible point (according to models):
    KernelScale      Lambda  
    ___________    __________

      3.2763       1.4374e-08

Estimated objective function value = 0.10143
Estimated function evaluation time = 51.861
Mdl = 
  ClassificationKernel
            PredictorNames: {'x1'  'x2'  'x3'  'x4'  'x5'  'x6'}
              ResponseName: 'Y'
                ClassNames: [0 1]
                   Learner: 'svm'
    NumExpansionDimensions: 256
               KernelScale: 3.2763
                    Lambda: 1.4374e-08
             BoxConstraint: 576.5789


  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') 
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 pair 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 memory
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1 sec
Evaluation completed in 1.3 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 'local':
- Pass 1 of 2: Completed in 0.9 sec
- Pass 2 of 2: Completed in 2.1 sec
Evaluation completed in 3.4 sec
|=====================================================================================================|
| Iter | Eval   | Objective   | Objective   | BestSoFar   | BestSoFar   |        sigma |       lambda |
|      | result |             | runtime     | (observed)  | (estim.)    |              |              |
|=====================================================================================================|
|    1 | Best   |     0.19649 |      157.57 |     0.19649 |     0.19649 |       1.2297 |     0.012135 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|    2 | Accept |     0.19649 |      195.79 |     0.19649 |     0.19649 |     0.039643 |   3.8633e-05 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|    3 | Accept |     0.19649 |      144.31 |     0.19649 |     0.19649 |      0.02562 |   1.8832e-08 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.5 sec
Evaluation completed in 1.7 sec
|    4 | Accept |     0.19649 |       92.09 |     0.19649 |     0.19649 |       92.644 |   1.8084e-07 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.5 sec
Evaluation completed in 1.6 sec
|    5 | Accept |     0.19649 |      102.21 |     0.19649 |     0.19649 |       978.95 |   0.00015066 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|    6 | Accept |     0.19649 |      153.49 |     0.19649 |     0.19649 |    0.0089609 |    0.0059189 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.6 sec
Evaluation completed in 1.8 sec
|    7 | Accept |     0.19649 |      151.92 |     0.19649 |     0.19649 |    0.0010228 |    1.292e-08 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.5 sec
Evaluation completed in 1.7 sec
|    8 | Accept |     0.19649 |      174.42 |     0.19649 |     0.19649 |      0.27475 |    0.0044831 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 2 sec
Evaluation completed in 2.2 sec
|    9 | Accept |     0.19649 |      145.09 |     0.19649 |     0.19649 |      0.81326 |   1.0753e-07 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 2.1 sec
Evaluation completed in 2.3 sec
|   10 | Accept |     0.19649 |      158.98 |     0.19649 |     0.19649 |    0.0040507 |   0.00011333 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2.1 sec
|   11 | Accept |     0.19649 |      102.02 |     0.19649 |     0.19649 |       330.84 |   0.00010095 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.5 sec
|   12 | Accept |     0.19649 |       96.16 |     0.19649 |     0.19649 |        65.19 |   0.00010513 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|   13 | Accept |     0.19649 |      99.916 |     0.19649 |     0.19649 |       46.548 |   1.2466e-08 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|   14 | Accept |     0.19649 |      100.04 |     0.19649 |     0.19649 |       721.08 |     0.012414 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.5 sec
Evaluation completed in 1.7 sec
|   15 | Accept |     0.19649 |      101.49 |     0.19649 |     0.19649 |       737.85 |   1.2515e-08 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.5 sec
Evaluation completed in 1.7 sec
|   16 | Accept |     0.19649 |      173.23 |     0.19649 |     0.19649 |     0.010073 |   3.3049e-05 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|   17 | Accept |     0.19649 |      157.35 |     0.19649 |     0.19649 |     0.025672 |   0.00019456 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|   18 | Accept |     0.19649 |      103.59 |     0.19649 |     0.19649 |        710.7 |    0.0021827 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2.1 sec
|   19 | Accept |     0.19649 |      170.31 |     0.19649 |     0.19649 |    0.0053051 |   0.00087841 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|   20 | Accept |     0.19649 |      173.82 |     0.19649 |     0.19649 |      0.12625 |     0.011292 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.5 sec
Evaluation completed in 1.7 sec
|=====================================================================================================|
| Iter | Eval   | Objective   | Objective   | BestSoFar   | BestSoFar   |        sigma |       lambda |
|      | result |             | runtime     | (observed)  | (estim.)    |              |              |
|=====================================================================================================|
|   21 | Accept |     0.19649 |       149.3 |     0.19649 |     0.19649 |      0.00149 |   5.8754e-07 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|   22 | Accept |     0.19649 |       98.03 |     0.19649 |     0.19649 |       52.749 |    1.265e-08 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 2 sec
Evaluation completed in 2.2 sec
|   23 | Best   |     0.10317 |       153.7 |     0.10317 |     0.10318 |       3.5534 |   0.00044046 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.6 sec
Evaluation completed in 1.8 sec
|   24 | Best   |     0.10282 |       140.2 |     0.10282 |     0.10271 |       3.6546 |   0.00024156 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|   25 | Accept |     0.11286 |      133.23 |     0.10282 |     0.10292 |       4.3231 |    0.0013656 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|   26 | Accept |     0.10409 |      156.29 |     0.10282 |     0.10304 |       3.4792 |   0.00021823 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|   27 | Accept |     0.11883 |      128.77 |     0.10282 |      0.1029 |        3.672 |    0.0027929 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.6 sec
|   28 | Accept |     0.10451 |      144.39 |     0.10282 |     0.10339 |       3.8815 |   0.00031253 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.4 sec
Evaluation completed in 1.5 sec
|   29 | Accept |     0.10374 |       141.5 |     0.10282 |     0.10339 |       3.6237 |    0.0003024 |
Evaluating tall expression using the Parallel Pool 'local':
- Pass 1 of 1: Completed in 1.9 sec
Evaluation completed in 2.1 sec
|   30 | Accept |     0.10362 |      165.36 |     0.10282 |     0.10336 |       3.6775 |   0.00024926 |

__________________________________________________________
Optimization completed.
MaxObjectiveEvaluations of 30 reached.
Total function evaluations: 30
Total elapsed time: 4343.3484 seconds.
Total objective function evaluation time: 4164.5815

Best observed feasible point:
    sigma       lambda  
    ______    __________

    3.6546    0.00024156

Observed objective function value = 0.10282
Estimated objective function value = 0.10336
Function evaluation time = 140.2034

Best estimated feasible point (according to models):
    sigma      lambda  
    ______    _________

    3.6237    0.0003024

Estimated objective function value = 0.10336
Estimated function evaluation time = 143.2776
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.1028
                   XAtMinObjective: [1×2 table]
             MinEstimatedObjective: 0.1034
          XAtMinEstimatedObjective: [1×2 table]
           NumObjectiveEvaluations: 30
                  TotalElapsedTime: 4.3433e+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.6237    0.0003024

The table zbest contains the optimal estimated values for the 'KernelScale' and 'Lambda' name-value pair 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.

Consulte también

| | | | | | | | | |