How to optimize the variables of a regression model
6 views (last 30 days)
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
Alan Weiss on 9 Aug 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);
Then call surrogateopt on the objective function @(x)objconstr(x,trainedModel).
MATLAB mathematical toolbox documentation