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!