According to Andrew Ng's lecture on logictic regression on Coursera the following cost function can be minimized using the update expression below:
Running that update function several hundred times on ~150 samples, I get the following pattern, though the cost seems to be decreasing after each iteration as expected:
The circles are the samples I'm training on, where the input features are the (x, y) coordinate of each point, and the color is the target label. The red or yellow background is what the model predicts that (x, y) input classifies as (red = 0, yellow = 1).
Question
- Is that update routine not the correct partial derivative of that corresponding cost function J?
- What can this output pattern be an indication of?
Training method
// A single pass/epoch
const lr = 0.003;
let params = [0.5, 0.5, 0.5];
const scores = samples.map(sample => sig(sum(sample, params));
const errors = scores.map((score, i) => score - labels[i][0]);
params = params.map((param, col) => {
return param - lr * errors.reduce((acc, error, row) => {
return acc + error * samples[row][col];
}, 0);
});
Sample training data
const samples = [
[1, 142, 78],
[1, 108, 182],
[1, 396, 47],
[1, 66, 102],
[1, 165, 116],
[1, 8, 106],
[1, 245, 119],
[1, 302, 17],
[1, 96, 38],
[1, 201, 132],
];
const labels = [
[0],
[1],
[0],
[0],
[1],
[1],
[1],
[0],
[1],
];
Edit
Here's a JSBin of this: https://jsbin.com/jinole/edit?html,js,output