How to extract hyper parameters during Bayesian optimization

조회 수: 7 (최근 30일)
Fab
Fab 2019년 3월 1일
댓글: Andrea Testa 2022년 3월 24일
Hi all,
I am new to using the bayesopt Matlab function and I was trying to test it on a toy problem.
I realize that bayesopt uses the "ardmatern52" Kernel function, which allows different length scales for multiple hyperparameters, and I wanted to have access to estimates of hyper parameters produced by the Bayesian Optimization function. In my understanding, these estimates are produced after evals by the fitrgp function; however, it seems that they somehow get lost and become unaccessible when a call to bayesopt is made. Any idea on how to access these estimates at the end of a Bayesian Optimization?
Currently working with R2016b
Thanks,
Fab

채택된 답변

Don Mathis
Don Mathis 2019년 3월 1일
There are many hidden properties in the BayesianOptimization object that is returned by bayesopt. One of them is ObjectiveFcnGP, which is the last Gaussian Process model that was fit to the observed function evaluation data. Here's an example of how to get the kernel parameters from that model (using R2018b):
Run bayesopt:
load ionosphere
rng default
num = optimizableVariable('n',[1,30],'Type','integer');
dst = optimizableVariable('dst',{'chebychev','euclidean','minkowski'},'Type','categorical');
c = cvpartition(351,'Kfold',5);
fun = @(x)kfoldLoss(fitcknn(X,Y,'CVPartition',c,'NumNeighbors',x.n,...
'Distance',char(x.dst),'NSMethod','exhaustive'));
results = bayesopt(fun,[num,dst],'Verbose',0,...
'AcquisitionFunctionName','expected-improvement-plus')
Get the final GP model:
gp = results.ObjectiveFcnGP
Get the kernel parameters from that:
gp.KernelInformation % look at kernel information
kparams = gp.KernelInformation.KernelParameters
You can see all the properties (hidden, private or otherwise) by doing this:
s = struct(results)
Then you can access what you want.
  댓글 수: 5
Don Mathis
Don Mathis 2022년 3월 23일
Try results.ObjectiveFcnModel.Model

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Model Building and Assessment에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by