MSE different in fitnlm vs. manually programmed
1 view (last 30 days)
Show older comments
Hello,
I was fitting specific model on the specific data with the fitnlm function.
The output structure for this, let's call it mdl, provides except anything else beta and Coefficients.Estimate data.
But when I used I used following my own function to evaluate MSE, which looks as pure as possible:
get_MSE = @(mdlfun, tr_x, tr_y, b) mean((tr_y-mdlfun(b, tr_x)).^2);
... there was little difference between
get_MSE = @(mdlfun, tr_x, tr_y, mdl.Coefficients.Estimate)
and
mdl.MSE
.
Do you have any idea, why?
Here is my whole illustratory code:
tr_x = rand([10, 2]);
tr_y = rand([10, 1]);
get_MSE = @(mdlfun, tr_x, tr_y, b) mean((tr_y-mdlfun(b, tr_x)).^2);
modelfun = @(b, tr_x) b(1)*tr_x(:, 1).*sin(b(2)*tr_x(:,2));
mdl = fitnlm(tr_x, tr_y, modelfun, [1 1]);
disp(mdl.MSE);
beta = mdl.Coefficients.Estimate;
disp(get_MSE(modelfun, tr_x, tr_y, beta));
Thanks in advance, best,
PL
0 Comments
Answers (0)
See Also
Categories
Find more on Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!