What is the difference between using cvpartition then calling it to kfoldLoss and using it directly in kfoldLoss?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I am based on the following link (https://fr.mathworks.com/help/stats/bayesopt.html) to produce the following code
clear all load ionosphere
%variables to optimize
box = optimizableVariable('box',[1e-4,1e3],'Transform','log');
kern = optimizableVariable('kern',[1e-4,1e3],'Transform','log');
s = rng % for reproductibility, Obtain the current state of the random stream
%%%%%%%%%%%%%%%%%%%%%%% FIRST PART%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%cross-validation
c = cvpartition(351,'Kfold',5);%351=number of examples in ionosphere
%function to minimize: cross-validation loss
vars = [box,kern];
fun = @(vars)kfoldLoss(fitcsvm(X,Y,'CVPartition',c,'BoxConstraint',vars.box,'KernelScale',vars.kern));
%optimization:Search for the parameters that give the lowest cross-validation error by using parallel Bayesian optimization.
results = bayesopt(fun,vars,'AcquisitionFunctionName','expected-improvement-plus');%results = bayesopt(fun,vars,'UseParallel',true,'AcquisitionFunctionName','expected-improvement-plus');
%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)
%%%%%%%%%%%%%%%%%%%%%%%% SECOND PART%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rng(s) % for reproductibility, Reset the stream to the previous state
fun2 = @(vars)kfoldLoss(fitcsvm(X,Y,'BoxConstraint',vars.box,'KernelScale',vars.kern,...
'Kfold',5));
results = bayesopt(fun2,vars);%,'AcquisitionFunctionName','expected-improvement-plus');
zbest2 = bestPoint(results)
I am wondering why I don't find the same results in the first and second part: in the first part, I defined the cvpartition and I called in fun. In the second part, I defined the cvpartition in the fun2.
Thank you in advance
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!