How can I evaluate the custom curve fitting result
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everyone!
As the title above? How can I figure out an index such as R-square to evaluate the custom curve fitting result? my solution: X=1:21; Y=[]; Custom function : Y=1./(1+exp(a*X+b)) After simplified: y=LN(1./Y-1)=a*X+b; The problem is transformed into a linear regression problem;
if true
p=polyfit(X,y,1);
x1=linspace(min(X),max(X));
py=1./(1+exp(a*x+b));
n=size(Y);
xba=mean(X);
yba=mean(py);
fengzi=0;
fengmuX=0;
fengmuY=0;
for i=1:n
fengzi=fengzi+((x(i)-xba)*(y(i)-yba));
fengmuX=fengmuX+(x(i)-xba)^2;
fengmuY=fengmuY+(y(i)-yba)^2;
end
fengmu=(fengmuX*fengmuY)^0.5;
R=fengzi/fengmu;
R-square=R*R;
end
Is that right?
0 Kommentare
Antworten (1)
Star Strider
am 6 Jul. 2014
It is incorrectly transformed into a linear regression problem. Taking the log of Y converts additive errors into multiplicative errors, violating the assumptions of least-squares parameter estimation. Only in the complete absence of noise will the estimated parameters be accurate.
It is relatively easy to use fminsearch to do a nonlinear curve fit to your exponential equation, and if your model is appropriate for your data, the estimated parameters will be reasonably accurate.
For example:
X=1:21;
Y=[something];
Yest = @(b,x) 1./(1+exp(b(1).*x+b(2))); % Objective function
OLS = @(b) sum((Y - Yest(b,X)).^2); % Cost function
b = fminsearch(OLS, [1; 1]) % Estimate parameters
Yfit = Yest(b,X); % Estimated Y-values
figure(1) % Plot data & fitted curve
plot(X, Y, '*r')
hold on
plot(X, Yfit, '-b')
hold off
grid
There are several ways to evaluate the fit. Probably the easiest is to create a (21 x 2) matrix of [Y; Yfit]' then call corrcoef:
[R, P, RLO, RUP] = corrcoef([Y; Yfit]')
0 Kommentare
Siehe auch
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!