GA codes for linear regression equation

4 ビュー (過去 30 日間)
Cornelius Bavoh
Cornelius Bavoh 2020 年 8 月 21 日
回答済み: Star Strider 2020 年 8 月 21 日
How can i code an optimization GA code for a multiple regression equation in the form Y=Ax1 +BX2 + C;
where X1 and X2 are variables and A,B,C are the constants for optimization.
Thanks in advance

採用された回答

Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020 年 8 月 21 日
Although ga() can fit multiple linear regression models, it is recommended to use regress() since it is dedicated to linear regression and is faster and more accurate than ga(). By the way, you can get this code from here:
https://www.mathworks.com/matlabcentral/answers/567840-genetic-algorithm-to-optimize-the-variable-of-linear-regression-a-b1-b2#answer_468399

その他の回答 (1 件)

Star Strider
Star Strider 2020 年 8 月 21 日
Since the fitness function must return a scalar value to the ga function, I would do something like this:
x = [x1(:) x2(:)]; % Matrix Of Column Vectors
y = y(:); % Column Vector
model = @(b,x) b(1).*x(:,1) + b(2).*x(:,2) + b(3); % Define Linear Regression Model
ftns = @(b) norm(y - model(b,x)); % Fitness Function
The ga function would then return the optimised values for the ‘b’ parameters. This approach can be used with any regression equation.
I have not tested this function specifically, however it should work.

カテゴリ

Help Center および File ExchangeLinear Regression についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by