first steps of the gradient descent chapter
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
function error = lsq_error(parameter, x, y)
|
||||
% parameter(1) is the slope
|
||||
% parameter(2) is the intercept
|
||||
% Objective function for fitting a linear equation to data.
|
||||
%
|
||||
% Arguments: parameter, vector containing slope and intercept (1st and 2nd element)
|
||||
% x, the input values
|
||||
% y, the measured system output
|
||||
%
|
||||
% Retruns: the estimation error in terms of the mean sqaure error
|
||||
|
||||
f_x = x .* parameter(1) + parameter(2);
|
||||
error = mean((f_x - y).^2);
|
||||
y_est = x .* parameter(1) + parameter(2);
|
||||
error = meanSquareError(y, y_est);
|
||||
|
||||
9
regression/code/mean_square_error.m
Normal file
9
regression/code/mean_square_error.m
Normal file
@@ -0,0 +1,9 @@
|
||||
function error = meanSquareError(y, y_est)
|
||||
% Function calculates the mean sqauare error between observed and predicted values.
|
||||
%
|
||||
% Agruments: y, the observed values
|
||||
% y_est, the predicted values.
|
||||
%
|
||||
% Returns: the error in the mean-square-deviation sense.
|
||||
|
||||
error = mean((y - y_est).^2);
|
||||
Reference in New Issue
Block a user