How to optimize the variables of a regression model

7 visualizaciones (últimos 30 días)
Simon Koch
Simon Koch el 9 de Ag. de 2021
Comentada: Alan Weiss el 16 de Ag. de 2021
Hello,
I have created a regression model using Statistics and Machine Learning Toolbox that is dependent on 6 variables. After exporting the model to the workspace, I now want to determine the global minimum of the function using "surrogateopt".
With my code, the solver varies the attributes in the specified interval, but the result of the output "fval" does not change.
Can anyone help me with this problem?
objconstr = @(x)trainedModel.predictFcn(data);
lb = [-10,-10,-10,-10,-10,-10];
ub = [10,10,10,10,10,10];
[x,fval] = surrogateopt(objconstr,lb,ub);
trainedModel.predictFcn is the name of the function
data is a table with the 6 attributes
Best
Simon

Respuesta aceptada

Alan Weiss
Alan Weiss el 9 de Ag. de 2021
I think that you need to connect your data argument to your x argument. Something like this:
function f = objconstr(x,trainedModel)
% Convert x to a table of the correct type.
% For example,
mytable = array2table(x,'VariableNames',...
["name1" "name2" "name3" "name4" "name5" "name6"); % Put in the appropriate names
y = trainedModel.predictFcn(mytable);
end
Then call surrogateopt on the objective function @(x)objconstr(x,trainedModel).
Alan Weiss
MATLAB mathematical toolbox documentation
  2 comentarios
Simon Koch
Simon Koch el 16 de Ag. de 2021
Thank you very much for your answer.
I have written the function in a separate script (objconstr.m).
function f = objconstr(x,trainedModel)
data = array2table(x,'VariableNames',["L1","L2","L3","R1","R2","R3"]);
f = trainedModel.predictFcn(data);
end
Now when I call surrogatopt in my original script (optimisation.m), an error message appears.
lb = [-1,-1,-1,-1,-1];
ub = [1,1,1,1,1];
[x,fval] = surrogateopt(@(x)objconstr(x,trainedModel),lb,ub);
Unable to find function @(x)trainedModel.predictFcn(TestData_new) within C:\Users\PCUser\Documents\MATLAB\optimisation.m.
Simon Koch
Alan Weiss
Alan Weiss el 16 de Ag. de 2021
Please perform the following experiment. Get trainedModel into your workspace and make sure that objconstr is on your MATLAB path. Then define fun = @(x)objconstr(x,trainedModel). Then take
x = zeros(1,6); % or any other feasible point
val = fun(x)
See whether this throws the same error. If so, then you have to figure out why before trying to optimize fun. If not, then I think that you are good to go, using fun inside surrogateopt.
Alan Weiss
MATLAB mathematical toolbox documentation

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surrogate Optimization en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by