I was plotting a 2D illustration of a simple logistic regression model, which takes two variables into account. The plot shows the datapoints in terms of the two variables in addition to the decision boundary. I am using R software to do that. I have followed some tutorials (such as this one on the Slender Means blog) and was able to plot the decision boundary and the datapoints successfully.
Now we can use the coefficients to plot a separating line in height-weight space.
logit_pars = male_logit.params intercept = -logit_pars['Intercept'] / logit_pars['Weight'] slope = -logit_pars['Height'] / logit_pars['Weight']
Let’s plot the data, color-coded by sex, and the separating line.
fig = plt.figure(figsize = (10, 8)) # Women points (coral) plt.plot(heights_f, weights_f, '.', label = 'Female', mfc = 'None', mec='coral', alpha = .4) # Men points (blue) plt.plot(heights_m, weights_m, '.', label = 'Male', mfc = 'None', mec='steelblue', alpha = .4) # The separating line plt.plot(array([50, 80]), intercept + slope * array([50, 80]), '-', color = '#461B7E') plt.xlabel('Height (in.)') plt.ylabel('Weight (lbs.)') plt.legend(loc='upper left')
Nevertheless, I noticed that the intercept of the decision boundary (in the code provided in the link) was defined as the beta-naught value (a.k.a., the intercept in R) divided by the coefficient of the first variable. The slope of the decision boundary was defined as the value of the coefficient of the second variable divided by the value of the coefficient of the first variable. I cannot understand how it is mathematically possible to get the intercept or the slope by doing this transformation. In other words, why wasn't the intercept used as it is instead of transforming it to plot the illustration?