bayesian optimization workflow -凯发k8网页登录

main content

bayesian optimization workflow

what is bayesian optimization?

optimization, in its most general form, is the process of locating a point that minimizes a real-valued function called the objective function. bayesian optimization is the name of one such process. bayesian optimization internally maintains a gaussian process model of the objective function, and uses objective function evaluations to train the model. one innovation in bayesian optimization is the use of an acquisition function, which the algorithm uses to determine the next point to evaluate. the acquisition function can balance sampling at points that have low modeled objective functions, and exploring areas that have not yet been modeled well. for details, see bayesian optimization algorithm.

bayesian optimization is part of statistics and machine learning toolbox™ because it is well-suited to optimizing hyperparameters of classification and regression algorithms. a hyperparameter is an internal parameter of a classifier or regression function, such as the box constraint of a support vector machine, or the learning rate of a robust classification ensemble. these parameters can strongly affect the performance of a classifier or regressor, and yet it is typically difficult or time-consuming to optimize them. see bayesian optimization characteristics.

typically, optimizing the hyperparameters means that you try to minimize the cross-validation loss of a classifier or regression.

ways to perform bayesian optimization

you can perform a bayesian optimization in several ways:

  • fitcauto and — pass predictor and response data to the fitcauto or fitrauto function to optimize across a selection of model types and hyperparameter values. unlike other approaches, using fitcauto or fitrauto does not require you to specify a single model before the optimization; model selection is part of the optimization process. the optimization minimizes cross-validation loss, which is modeled using a multi-treebagger model in fitcauto and a multi-regressiongp model in fitrauto, rather than a single gaussian process regression model as used in other approaches. see bayesian optimization for fitcauto and for fitrauto.

  • classification learner and regression learner apps — choose optimizable models in the machine learning apps and automatically tune their hyperparameter values by using bayesian optimization. the optimization minimizes the model loss based on the selected validation options. this approach has fewer tuning options than using a fit function, but allows you to perform bayesian optimization directly in the apps. see hyperparameter optimization in classification learner app and .

  • fit function — include the optimizehyperparameters name-value argument in many fitting functions to apply bayesian optimization automatically. the optimization minimizes cross-validation loss. this approach gives you fewer tuning options than using bayesopt, but enables you to perform bayesian optimization more easily. see bayesian optimization using a fit function.

  • — exert the most control over your optimization by calling bayesopt directly. this approach requires you to write an objective function, which does not have to represent cross-validation loss. see bayesian optimization using bayesopt.

bayesian optimization using a fit function

to minimize the error in a cross-validated response via bayesian optimization, follow these steps.

  1. choose your classification or regression solver among the fit functions that accept the optimizehyperparameters name-value argument.

  2. decide on the hyperparameters to optimize, and pass them in the optimizehyperparameters name-value argument. for each fit function, you can choose from a set of hyperparameters. see eligible hyperparameters for fit functions, or use the function, or consult the fit function reference page.

    you can pass a cell array of parameter names. you can also set 'auto' as the optimizehyperparameters value, which chooses a typical set of hyperparameters to optimize, or 'all' to optimize all available parameters.

  3. for ensemble fit functions fitcecoc, fitcensemble, and fitrensemble, also include parameters of the weak learners in the optimizehyperparameters cell array.

  4. optionally, create an options structure for the hyperparameteroptimizationoptions name-value argument. see hyperparameter optimization options for fit functions.

  5. call the fit function with the appropriate name-value arguments.

for examples, see and . also, every fit function reference page contains a bayesian optimization example.

bayesian optimization using bayesopt

to perform a bayesian optimization using , follow these steps.

  1. prepare your variables. see .

  2. create your objective function. see . if necessary, create constraints, too. see . to include extra parameters in an objective function, see .

  3. decide on options, meaning the bayseopt pairs. you are not required to pass any options to but you typically do, especially when trying to improve a solution.

  4. call .

  5. examine the solution. you can decide to resume the optimization by using , or restart the optimization, usually with modified options.

for an example, see .

bayesian optimization characteristics

bayesian optimization algorithms are best suited to these problem types.

characteristicdetails
low dimension

bayesian optimization works best in a low number of dimensions, typically 10 or fewer. while bayesian optimization can solve some problems with a few dozen variables, it is not recommended for dimensions higher than about 50.

expensive objective

bayesian optimization is designed for objective functions that are slow to evaluate. it has considerable overhead, typically several seconds for each iteration.

low accuracy

bayesian optimization does not necessarily give very accurate results. if you have a deterministic objective function, you can sometimes improve the accuracy by starting a standard optimization algorithm from the bayesopt solution.

global solution

bayesian optimization is a global technique. unlike many other algorithms, to search for a global solution you do not have to start the algorithm from various initial points.

hyperparameters

bayesian optimization is well-suited to optimizing hyperparameters of another function. a hyperparameter is a parameter that controls the behavior of a function. for example, the fitcsvm function fits an svm model to data. it has hyperparameters boxconstraint and kernelscale for its 'rbf' kernelfunction. for an example of bayesian optimization applied to hyperparameters, see .

parameters available for fit functions

eligible hyperparameters for fit functions

function nameeligible parameters
fitcdiscrdelta
gamma
discrimtype
fitcecoccoding
eligible fitcdiscr parameters for 'learners','discriminant'
eligible parameters for 'learners','kernel'
eligible fitcknn parameters for 'learners','knn'
eligible fitclinear parameters for 'learners','linear'
eligible fitcsvm parameters for 'learners','svm'
eligible fitctree parameters for 'learners','tree'
fitcensemblemethod
numlearningcycles
learnrate
eligible fitcdiscr parameters for 'learners','discriminant'
eligible fitcknn parameters for 'learners','knn'
eligible fitctree parameters for 'learners','tree'









fitcknnnumneighbors
distance
distanceweight
exponent
standardize
fitclinearlambda
learner
regularization
fitcnbdistributionnames
width
kernel
fitcnetactivations
lambda
layerbiasesinitializer
layerweightsinitializer
layersizes
standardize
fitcsvmboxconstraint
kernelscale
kernelfunction
polynomialorder
standardize
fitctreeminleafsize
maxnumsplits
splitcriterion
numvariablestosample



eligible fitrtree parameters for 'learners','tree':
minleafsize
maxnumsplits
numvariablestosample






fitrgpsigma
basisfunction
kernelfunction
kernelscale
standardize




fitrlinearlambda
learner
regularization





fitrsvmboxconstraint
kernelscale
epsilon
kernelfunction
polynomialorder
standardize
fitrtreeminleafsize
maxnumsplits
numvariablestosample

hyperparameter optimization options for fit functions

when optimizing using a fit function, you have these options available in the hyperparameteroptimizationoptions name-value argument. give the value as a structure. all fields in the structure are optional.

field namevaluesdefault
optimizer
  • 'bayesopt' — use bayesian optimization. internally, this setting calls .

  • 'gridsearch' — use grid search with numgriddivisions values per dimension.

  • 'randomsearch' — search at random among maxobjectiveevaluations points.

'gridsearch' searches in a random order, using uniform sampling without replacement from the grid. after optimization, you can get a table in grid order by using the command sortrows(mdl.hyperparameteroptimizationresults).

'bayesopt'
acquisitionfunctionname
  • 'expected-improvement-per-second-plus'

  • 'expected-improvement'

  • 'expected-improvement-plus'

  • 'expected-improvement-per-second'

  • 'lower-confidence-bound'

  • 'probability-of-improvement'

acquisition functions whose names include per-second do not yield reproducible results because the optimization depends on the runtime of the objective function. acquisition functions whose names include plus modify their behavior when they are overexploiting an area. for more details, see acquisition function types.

'expected-improvement-per-second-plus'
maxobjectiveevaluationsmaximum number of objective function evaluations.30 for 'bayesopt' and 'randomsearch', and the entire grid for 'gridsearch'
maxtime

time limit, specified as a positive real scalar. the time limit is in seconds, as measured by tic and toc. the run time can exceed maxtime because maxtime does not interrupt function evaluations.

inf
numgriddivisionsfor 'gridsearch', the number of values in each dimension. the value can be a vector of positive integers giving the number of values for each dimension, or a scalar that applies to all dimensions. this field is ignored for categorical variables.10
showplotslogical value indicating whether to show plots. if true, this field plots the best observed objective function value against the iteration number. if you use bayesian optimization (optimizer is 'bayesopt'), then this field also plots the best estimated objective function value. the best observed objective function values and best estimated objective function values correspond to the values in the bestsofar (observed) and bestsofar (estim.) columns of the iterative display, respectively. you can find these values in the properties objectiveminimumtrace and estimatedobjectiveminimumtrace of mdl.hyperparameteroptimizationresults. if the problem includes one or two optimization parameters for bayesian optimization, then showplots also plots a model of the objective function against the parameters.true
saveintermediateresultslogical value indicating whether to save results when optimizer is 'bayesopt'. if true, this field overwrites a workspace variable named 'bayesoptresults' at each iteration. the variable is a bayesianoptimization object.false
verbose

display at the command line:

  • 0 — no iterative display

  • 1 — iterative display

  • 2 — iterative display with extra information

for details, see the bayesopt name-value argument and the example .

1
useparallellogical value indicating whether to run bayesian optimization in parallel, which requires parallel computing toolbox™. due to the nonreproducibility of parallel timing, parallel bayesian optimization does not necessarily yield reproducible results. for details, see .false
repartition

logical value indicating whether to repartition the cross-validation at every iteration. if this field is false, the optimizer uses a single partition for the optimization.

the setting true usually gives the most robust results because it takes partitioning noise into account. however, for good results, true requires at least twice as many function evaluations.

false
use no more than one of the following three options.
cvpartitiona cvpartition object, as created by cvpartition'kfold',5 if you do not specify a cross-validation field
holdouta scalar in the range (0,1) representing the holdout fraction
kfoldan integer greater than 1

see also

|

related topics

网站地图