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 Center および File ExchangeSurrogate Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by