How can I evaluate the custom curve fitting result

조회 수: 1 (최근 30일)
Hui
Hui 2014년 7월 6일
답변: Star Strider 2014년 7월 6일
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?

답변 (1개)

Star Strider
Star Strider 2014년 7월 6일
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]')

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by