# What is wrong with my logistic regression implementation?

Recently, I implemented the LR algorithm in Python. The main part of the code is as following(I didn't use mini batch in my code. Instead, I use the whole batch to compute gradients every time):

class Logistic():
def __init__(self):
self.w = None
self.lr = 10.
pass
def train(self, xs, ys):
m, n = xs.shape
ones = np.ones([m, 1])
xs = np.hstack([xs, ones])
ys = np.expand_dims(ys, -1)
self.w = np.ones([n+1, 1], dtype=np.float64) * 1.0
epochs = 100
for epoch in xrange(epochs):
y_ = self.sigmoid(-np.dot(xs, self.w))
# loss = -1.0/m * np.sum(ys * np.log(y_) + (1 - ys) * np.log(1 - y_))
tmp1 = np.sum(np.log(y_[np.where(ys==1)]))
tmp2 = np.sum(np.log(1 - y_[np.where(ys==0)]))
loss = - (tmp1 + tmp2) / m
print("epoch: %d, loss: %f" % (epoch, loss))
print("y_: %f, %f" % (np.min(y_), np.max(y_)))
grad =  np.sum((y_ - ys) * xs, axis=0) / m
self.w -= self.lr * np.expand_dims(grad, -1)

• What is the proportion of $0$'s in your dataset (I presume it is 10 % in which accuracy is misleading, since a dummy classifier can make 90 % by assigning each given sample to class non-zero)? What is your classification threshold? Can you provide a confusion matrix also? – gunes Apr 2 at 11:34