How to optimize the variables of a regression model

조회 수: 9 (최근 30일)
Simon Koch
Simon Koch 2021년 8월 9일
댓글: Alan Weiss 2021년 8월 16일
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