0

Correct me if I'm wrong, but I heard that Logistic Regression takes the Linear Regression of the data as a "variable" (instead of x), such that:

n

Is it true? cause for the code below I got different coefficients for the same data:

data = pd.read_csv('logistic_reg.csv')

scores = data['score']
states = data['approved']

x = np.array(scores).reshape(-1,1)
y = np.array(states)


model = LinearRegression().fit(x,y)
print(model.coef_)
print(model.intercept_)

model = LogisticRegression().fit(x,y)
print(model.coef_)
print(model.intercept_)
[0.00270938]
-1.050025042121259
[[0.04209124]]
[-23.95021449]

Thanks for your answers.

  • Please show a data set (or include code to generate one) that can be used by everyone to reproduce your result. Thanks. (In the general case, you cannot assume that the learned coefficients of linreg and logreg are the same.) – Mathias Müller Aug 12 '20 at 12:10
  • @Mathias Müller according to this tutorial I guessed that the coefficients are the same: https://www.youtube.com/watch?v=zM4VZR0px8E&t=908s But here is the dataset: https://drive.google.com/file/d/1NvBCh8tukbtcpyl8TLmdxt5FFtmIwSeH/view?usp=sharing –  Aug 12 '20 at 13:56
  • I guess you are mixing the word "regression" used in both methods. Logistic regression is meant to solve classification problems. In simple words, Logistic regression doesn't predict continuous values like simple linear regression. Please go through the following link: https://stackoverflow.com/questions/12146914/what-is-the-difference-between-linear-regression-and-logistic-regression#:~:text=In%20linear%20regression%2C%20the%20outcome,limited%20number%20of%20possible%20values.&text=Logistic%20regression%20is%20used%20when%20the%20response%20variable%20is%20categorical%20in%20nature. – Muhammad Shahzad Aug 12 '20 at 14:05
  • I know that logistic regression predicts probability in contrast to linear regression which predicts a value... it doesn't answer the question –  Aug 12 '20 at 17:11
  • What reason do you have to think they should be the same? The form of logistic regression is S(R(x)), and the coefficients are estimated/optimized for that form, whereas the coefficients in linear regression are estimated for just R(x). – Ben Reiniger Aug 12 '20 at 20:18
  • @BenReiniger then they way the coefficients are optimized are totally different? and if so, what's the method that optimizes the coefficients of the logistic regression function? –  Aug 12 '20 at 20:27

0 Answers0