Compute cost for multiple variables
This commit is contained in:
		
							parent
							
								
									e38033c00d
								
							
						
					
					
						commit
						3dc8897634
					
				
					 1 changed files with 4 additions and 0 deletions
				
			
		| 
						 | 
					@ -13,7 +13,11 @@ J = 0;
 | 
				
			||||||
% Instructions: Compute the cost of a particular choice of theta
 | 
					% Instructions: Compute the cost of a particular choice of theta
 | 
				
			||||||
%               You should set J to the cost.
 | 
					%               You should set J to the cost.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					predictions = X * theta;
 | 
				
			||||||
 | 
					errors = predictions - y;
 | 
				
			||||||
 | 
					squared_errors = errors .^ 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					J = 1/(2*m) * sum(squared_errors);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
% =========================================================================
 | 
					% =========================================================================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue