MATLAB Answers

bayesopt of patternet in classification problems

3 views (last 30 days)
Giovanni Barbarossa
Giovanni Barbarossa on 20 Apr 2020
I would like to optimize the variables of patternet for a classification problem using bayesopt. I found online the example below which optimizes the number of hidden layers and the learning rate:
% Define a train/validation split to use inside the objective function
cv = cvpartition(numel(YTrain), 'Holdout', 1/3);
% Define hyperparameters to optimize
vars = [optimizableVariable('hiddenLayerSize', [1,20], 'Type', 'integer');
optimizableVariable('lr', [1e-3 1], 'Transform', 'log')];
% Optimize
minfn = @(T)kfoldLoss(XTrain', YTrain', cv, T.hiddenLayerSize,;
results = bayesopt(minfn, vars,'IsObjectiveDeterministic', false, ...
'AcquisitionFunctionName', 'probability-of-improvement', ...
function rmse = kfoldLoss(x, y, cv, numHid, lr)
% Train net.
net = patternnet(numHid, 'traingd'); = lr;
net = train(net, x(:,, y(:,;
% Evaluate on validation set and compute rmse
ypred = net(x(:, cv.test));
rmse = sqrt(mean((ypred - y(cv.test)).^2));
Which other variables of patternet can I optimize? Can I optimize them all? Is there an official Matlab documentation for patternet like there is one for fitcensemble to optimize the hyperparameters in classification problems using bayesopt? I can’t find in the official Matlab documentation the variables of patternet that I can actually optimize, and then how to implement them in the code above. I found epochs, goal and others but only in some examples online.


Sign in to comment.

Answers (0)

Translated by