I am trying to implement Stochastic Gradient Descent
algorithm for logistic regression. I have written a small train
function whose job is to get the theta
values / coefficients. But the values of theta
come out to be incorrect and are same as the one initialised. I could not understand the reason for this. Is it not the correct way to implement stochastic gradient descent?
Here is the code I wrote for it:
train <- function(data, labels, alpha = 0.0009) {
theta <- seq(from = 0, to = 1, length.out = nrow(data))
label <- label[,shuffle]
data <- data[,shuffle]
for(i in seq(1:ncol(data))) {
h = hypothesis(x, theta)
theta <- theta - (alpha * ((h - y) * data[,i]))
}
return(theta)
}
Please note that, each column in the data frame is one input. There are 20K columns and 456 rows. So, 20K input values for training. The corresponding data frame named labels
has the correct value for the input training data. So for example column 45 in data
has its corresponding y
value in column 45 of labels
.
In the regression above, I am trying to train to predict between the label 1
and label 0
. So labels
is a data frame that comprises of 0
and 1
.