Finding best fit function for a data set
51 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
Respuestas (2)
Sulaymon Eshkabilov
el 9 de Feb. de 2023
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 comentarios
Arka
el 9 de Feb. de 2023
Editada: Arka
el 9 de Feb. de 2023
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 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!