Back to problems

Logistic Regression Debugging

Algorithm · LinkedIn · Hard

You are provided with an implementation of logistic regression training in Python. The code is intended to compute the gradient of the mean binary cross-entropy loss with respect to the weight vector. However, the implementation contains several mathematical and implementation errors. Your task is to identify and correct these defects. The correct gradient for the weight vector w is given by: $$\nabla_w L = \frac{1}{m} X^\top (h - y)$$ where: m is the number of training…

Checking your access…