This is a quick list of functions for computing regularized logistic regressions:

The logistic equation in matlab format is:

h = 1 / (1 + exp(-x))) % In the case where x is a vector or matrix, you’ll want to use an index loop for rows and columns, and compute for the entire vector or Array and assign to a return vector/array.

This creates a cost function that looks like this:

and gradients that look like this:

*sigX = sigmoid(X*theta); % this is a vector of sigmoid values, as theta is a vector.*

*grad(gradCtr) = 1/m * ((sigX-y)’ * X(:,gradCtr)) + lambda/m*theta(gradCtr); % remember sigX is a vector of values where each element is between 0 and 1, and y is a label vector with elements exclusively 0 or 1.*

Here, gradCtr is a loop iterator from 2 to the end of the theta array. You car arrive at the above by taking the derivate of the cost function and simplifying it.

### Like this:

Like Loading...

*Related*

## Leave a Reply