Connect your moderator Slack workspace to receive post notifications:
Sign in with Slack

Predictions in logistic regression

For logistic regression, do we need to adapt this function so that we apply the sigmoid function to the np.dot(data, weights)?

Code
def predict_labels(weights, data, logistic):
"""Generates class predictions given weights, and a test data matrix"""
if logistic:
threshold = 0.5
else:
threshold = 0

y_pred = np.dot(data, weights)
y_pred[np.where(y_pred <= threshold)] = -1
y_pred[np.where(y_pred > threshold)] = 1

return y_pred

Code

Hi,

np.dot(data, weights) > 0 if and only if sigmoid(np.dot(data, weights)) > 0.5

So if I understand your question correctly, you should just make sure that threshold=0 in your code (i.e. logistic=False in your code which is probably a bit misleading as it should be vice versa).

Page 1 of 1

Add comment

Post as Anonymous Dont send out notification