23 lines
572 B
Matlab
23 lines
572 B
Matlab
load('lin_regression.mat');
|
|
|
|
% compute mean squared error for a range of slopes and intercepts:
|
|
slopes = -5:0.25:5;
|
|
intercepts = -30:1:30;
|
|
error_surf = zeros(length(slopes), length(intercepts));
|
|
for i = 1:length(slopes)
|
|
for j = 1:length(intercepts)
|
|
error_surf(i,j) = lsqError([slopes(i), intercepts(j)], x, y);
|
|
end
|
|
end
|
|
|
|
% plot the error surface:
|
|
figure()
|
|
[N,M] = meshgrid(intercepts, slopes);
|
|
s = surface(M, N, error_surf);
|
|
xlabel('slope', 'rotation', 7.5)
|
|
ylabel('intercept', 'rotation', -22.5)
|
|
zlabel('error')
|
|
set(gca,'xtick', (-5:2.5:5))
|
|
grid on
|
|
view(3)
|