How to optimize the variables of a regression model

9 次查看(过去 30 天)
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

采纳的回答

Alan Weiss
Alan Weiss 2021-8-9
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 个评论
Simon Koch
Simon Koch 2021-8-16
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 2021-8-16
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surrogate Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by