Week 1: Visualizing tweets and the logistic regression model: direction

Hello. In the lab Visualizing tweets and the logistic regression model, in section ‘Plot the model alongside the data’, there are these lines:

"The red and green lines that point in the direction of the corresponding sentiment are calculated using a perpendicular line to the separation line calculated in the previous equations (neg function). It must point in the same direction as the derivative of the Logit function, but the magnitude may differ. It is only for a visual representation of the model.

direction = pos * \theta_2 / \theta_1"

Could someone please explain to me how we get to the formula in direction?

Thank you!

Hi @Erika_Petersen

The decision boundary is defined by the equation \theta_1 x_1 + \theta_2 x_2 + \theta_0 = 0. The direction vector (\theta_1, \theta_2), shows the gradient of the decision function.

To visualize the direction of the sentiment (+ / -), we scale this vector so it points in the same direction as the gradient of the LR, but the magnitude can vary. So, the formula direction = pos * \theta_2 / \theta_1 provides the slope of this direction vector, showing the model’s decision boundary in a way that aligns with the sentiment’s gradient.

Hope this helps, feel free to ask if you need further assistance!

Note: To use LaTeX notation on the forum, you only need one $ as framing (not a pair).

Thank you! This was helpful!

Thank you very much! I’ve updated my original post to remove the double ‘$’.

1 Like

You’re welcome! Happy to help :raised_hands: