Finding best fit function for a data set
조회 수: 52 (최근 30일)
이전 댓글 표시
Hi All, I have a set of X,Y,Z Data and I am trying to find the best fit equation between the input variables (X,Y) and the output variable (Z). I have been manually trying different functions that and so far the best function I have came up with is (Z = Log(X*Y) with R2 of 0.59) I am not sure if there is an automated way to find even more best fitting equation for this data. I have attached the excel sheet that contain the data. Thanks in advance for your help.
답변 (2개)
Sulaymon Eshkabilov
2023년 2월 9일
You can try cftool - curve fitting toolbox, or use fit(), e.g.:
D = readmatrix('Samples_Data.xlsx');
X = D(:,2);
Y = D(:,3);
Z = D(:,4);
FModel = fit([X,Y], Z, 'poly23');
plot(FModel, [X, Y], Z)
[FModel, Fit_quality]=fit([X,Y], Z, 'poly23')
댓글 수: 0
Arka
2023년 2월 9일
편집: Arka
2023년 2월 9일
Hello,
From what I understood, you have a 3 variable dataset, and you would like to automate the process of getting a line of best fit for the dataset.
You can use the ‘fit’ function and its supported polynomial solvers to automate the process of finding a polynomial best fit function for the dataset.
The code for the same is given below:
data = readmatrix('Samples_Data.xlsx');
x = data(:, 2);
y = data(:, 3);
z = data(:, 4);
solvers = ["poly11", "poly12", "poly13", "poly21", "poly22", "poly23", "poly31", "poly32", "poly33", "poly41"];
rSq = 0;
bestModel = 0;
for i=1:size(solvers, 2)
[model, goodnessOfFit] = fit([x, y], z, solvers(i));
if goodnessOfFit.rsquare > rSq
rSq = goodnessOfFit.rsquare;
bestModel = model;
end
end
bestModel
plot(bestModel, [x, y], z)
The output gives us the best fit function (and the solver used for it):
The plot is given below:
You can refer to the documentation link for the ‘fit’ function below:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!