Skip to content

Instantly share code, notes, and snippets.

View abulhoroof's full-sized avatar
:shipit:

Amine Fouad Djebbar abulhoroof

:shipit:
View GitHub Profile
@drio
drio / linearRegCostFunction.m
Created November 18, 2011 21:42
Nice way to vectorize the gradient terms when working on linear regression
function [J, grad] = linearRegCostFunction(X, y, theta, lambda)
%LINEARREGCOSTFUNCTION Compute cost and gradient for regularized linear
%regression with multiple variables
% [J, grad] = LINEARREGCOSTFUNCTION(X, y, theta, lambda) computes the
% cost of using theta as the parameter for linear regression to fit the
% data points in X and y. Returns the cost in J and the gradient in grad
% Initialize some useful values
m = length(y); % number of training examples