From 14c85aa85cdb727cc48eabdb1198d75094a9a169 Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 1 Oct 2014 22:05:13 +0200 Subject: [PATCH] Compute Cost (for one variable) --- ex1/computeCost.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ex1/computeCost.m b/ex1/computeCost.m index 93eb14c..cee9e25 100644 --- a/ex1/computeCost.m +++ b/ex1/computeCost.m @@ -6,16 +6,18 @@ function J = computeCost(X, y, theta) % Initialize some useful values m = length(y); % number of training examples -% You need to return the following variables correctly +% You need to return the following variables correctly J = 0; % ====================== YOUR CODE HERE ====================== % Instructions: Compute the cost of a particular choice of theta % You should set J to the cost. +predictions = X * theta; +errors = predictions - y; +squared_errors = errors .^ 2; - - +J = 1/(2*m) * sum(squared_errors); % =========================================================================