How to add limits on fitting parameters in regressionLearner

조회 수: 6 (최근 30일)
Jule
Jule 2021년 1월 7일
답변: KALASH 2024년 2월 28일
I have a dataset with one response variable CO2 and three input variables (XCO2, T, P) that I'm trying to fit with the linear quadratic model in the regressionLearner. So the function in the end would look like this:
CO2 = intercept + A*XCO2 + B*T + C*P + D*XCO2*T + E*XCO2*P + F*T*P + G*XCO2^2 + H*T^2 + J*P^2
where intercept, A, B, C,... are the fitting parameters.
I need the result to be zero for XCO2 =0, but I cannot find a way to put any constraints on the fitting parameters in the regressionLearner tool. Do you know of a way to add limits on the individual fitting parameters or alternatively on how to add weights to the data points, so that I could force a zero-intercept?
Or is there a better way to come up with a polynomial fit for multiple input variables?

답변 (1개)

KALASH
KALASH 2024년 2월 28일
Hi Jule,
I understand from your question that you want to add limits to your fitting parameters. I checked the Regression Learner app and could not find any option to put a limit on the parameters. I found that although you have an option to put a range on the “hyperparameters” (not in the linear models but only in quadratic and other models) but you cannot change the “fitting parameters of the equation using the app because they are the coefficients that the model learns while getting trained so for that you need to customise the code. Have a look at the following reference for better understanding
As I do not have access to your code, I am making some basic assumptions:
  • Saved the model in a variable after training it in the Regression Learner app
  • Used a linear model as you stated in the question
Below is the part which you can use in your existing code to change the coefficients:
%.........your code.........
%fit the model using the regression learner app and save the model with a name
%extract the coefficients
Coeff = model_name.Coefficients.Estimate;
Coeff(1) = 0; %setting the intercept to zero
%manually create new model for e.g., if you are creating a linear model
modifiedModel = LinearModel.fit(X, Y, linear, Coefficients, Coeff);
%......end......
I hope you got the idea. You may refer to the MATLAB R2020b documentation for the Regression Learner app here:

카테고리

Help CenterFile Exchange에서 Least Squares에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by