Skip to content

Latest commit

ย 

History

History
354 lines (237 loc) ยท 13.5 KB

logistic-regression.md

File metadata and controls

354 lines (237 loc) ยท 13.5 KB

๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€ (Logistic Regression)

๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€(Logistic Regression)๋Š” ์„ ํ˜• ํšŒ๊ท€ ๋ฐฉ์‹์„ ์‘์šฉํ•ด ๋ถ„๋ฅ˜ (Classification)์— ์ ์šฉํ•œ ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค. ๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€๋Š” ๊ฐ„๋‹จํ•˜๋ฉด์„œ๋„ ํŒŒ๋ผ๋ฏธํ„ฐ ์ˆ˜๊ฐ€ ๋งŽ์ง€ ์•Š์•„ ๋น ๋ฅด๊ฒŒ ์˜ˆ์ธกํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ) ์ฃผ์ฐจ์žฅ์— ๋นˆ์ž๋ฆฌ๊ฐ€ ์žˆ๋Š”์ง€๋ฅผ ์ถ”์ •

๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€๋Š” Sigmoid function์„ ํ™œ์šฉํ•ด ํƒ€๊นƒ๊ฐ’์— ํฌํ•จ๋  ํ™•๋ฅ ์„ ์˜ˆ์ธกํ•ฉ๋‹ˆ๋‹ค.

ํŠน์ง•

ํผ์…‰ํŠธ๋ก  (Perceptron)๊ณผ ๋น„์Šทํ•œ ํŠน์ง•์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

  • ์ถœ๋ ฅ๊ณผ ๋ณ„๋„๋กœ ์ถœ๋ ฅ๊ฐ’์— ํ•ด๋‹นํ•˜๋Š” ํด๋ž˜์Šค์— ์†ํ•  ํ™•๋ฅ ์„ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์˜จ๋ผ์ธ ํ•™์Šต๊ณผ ๋ฐฐ์น˜ ํ•™์Šต์— ๋ชจ๋‘ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ์˜ˆ์ธก ์„ฑ๋Šฅ์€ ๋ณดํ†ต์ด์ง€๋งŒ ํ•™์Šต ์†๋„๊ฐ€ ๋น ๋ฅด๋‹ค
  • ๊ณผ์ ํ•ฉ์„ ๋ฐฉ์ง€ํ•˜๋Š” ๊ทœ์ œํ•ญ์ด ์ถ”๊ฐ€๋˜์–ด ์žˆ๋‹ค.
  • ํŠนํžˆ ์ถœ๋ ฅ์˜ ํ™•๋ฅ ์„ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ํŠน์„ฑ์„ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์„œ ๊ด‘๊ณ ๋กœ ์ธํ•œ ํด๋ฆญ ์˜ˆ์ธก๊ณผ ๊ฐ™์€ ๋ถ„์•ผ์—๋„ ํ™œ์šฉ๋œ๋‹ค.
  • Logistic Regression์€ ์„ ํ˜• ๋ถ„๋ฆฌ ๊ฐ€๋Šฅํ•œ ๋Œ€์ƒ์„ ๋ถ„๋ฆฌํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋ฏ€๋กœ ๊ฒฐ์ •๊ฒฝ๊ณ„๊ฐ€ ์ง์„ ์ž…๋‹ˆ๋‹ค.

Logistric Regression๊ณผ Perceptron์˜ ์ฐจ์ด์ 

  • ํ™œ์„ฑํ™”ํ•จ์ˆ˜๋กœ Sigmoid ํ•จ์ˆ˜ ๋˜๋Š” Logistic sigmoid function์„ ์”๋‹ˆ๋‹ค.
  • ์†์‹คํ•จ์ˆ˜๋กœ ๊ต์ฐจ ์—”ํŠธ๋กœํ”ผ ์˜ค์ฐจ ํ•จ์ˆ˜(Cross-entropy error function)์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • ๊ทœ์ œํ•ญ(Regularization term)์ด ์ถ”๊ฐ€๋˜์–ด์„œ ๊ณผ์ ํ•ฉ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์˜จ๋ผ์ธํ•™์Šต๊ณผ ๋ฐฐ์น˜ํ•™์Šต์— ๋ชจ๋‘ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Linear Regression Vs. Logistic Regression

Logistric Regression์€ Linear Regression๊ณผ ๋น„์Šทํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. Logistic Regression์€ ๊ฐ ํŠน์„ฑ(feature)์— ๋Œ€ํ•ด ๋ชจ๋ธ ์ •ํ™•๋„๋ฅผ ์ตœ๋Œ€ํ™”ํ•˜๋Š” ์ ์ ˆํ•œ ๊ฐ€์ค‘์น˜(weight) ๋˜๋Š” ๊ณ„์ˆ˜(coefficient)๋ฅผ ์ฐพ์Šต๋‹ˆ๋‹ค. ์„ ํ˜•ํšŒ๊ท€์ฒ˜๋Ÿผ ๊ฐ ํ•ญ์˜ ํ•ฉ์˜ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋Š” ๋Œ€์‹  Logistic Regression์€ Sigmoid Function์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.

Linear regression gives you a continuous output, but logistic regression provides a constant output. An example of the continuous output is house price and stock price. Example's of the discrete output is predicting whether a patient has cancer or not, predicting whether the customer will churn. Linear regression is estimated using Ordinary Least Squares (OLS) while logistic regression is estimated using Maximum Likelihood Estimation (MLE) approach.

image

Logstic Regression ์˜ˆ์ œ

logistic_regression.ipynb๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

๋ฐ์ดํ„ฐ ์ค€๋น„

์•„๋ž˜์™€ ๊ฐ™์ด pandas๋ฅผ ํ†ตํ•ด fish data๋ฅผ ๋กœ๋”ฉํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ฐ์ดํ„ฐ๋Š” ์บ๊ธ€์˜ Red Wine Quality์— ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ, fish_csv_data๋Š” ํ˜ผ์ž ๊ณต๋ถ€ํ•˜๋Š” ๋จธ์‹ ๋Ÿฌ๋‹+๋”ฅ๋Ÿฌ๋‹์—์„œ ๊ฐ€์ ธ์™”์Šต๋‹ˆ๋‹ค.

import pandas as pd

fish = pd.read_csv('https://bit.ly/fish_csv_data')
fish.head()

์•„๋ž˜์™€ ๊ฐ™์€ fish ๋ฐ์ดํ„ฐ๋ฅผ ๋กœ๋“œํ•˜์˜€์Šต๋‹ˆ๋‹ค. ํ‘œ์ค€์ ์ˆ˜(z)๋Š” "z = a * Weight + b * Length + c * Diagonal + d * Height + e * Width + f"์™€ ๊ฐ™์ด ํ‘œํ˜„๋ฉ๋‹ˆ๋‹ค.

image

์ด๋•Œ ์ฝ์–ด์˜จ fish ๋ฐ์ดํ„ฐ๋Š” "Bream", "Roach", "Whitefish", "Parkki", "Perch", "Pike", "Smelt"์ด ์žˆ์Šต๋‹ˆ๋‹ค.

Numpyํฌ๋งท์œผ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

fish_input = fish[['Weight','Length','Diagonal','Height','Width']].to_numpy()
print(fish_input[:5])

[[242.      25.4     30.      11.52     4.02  ]
 [290.      26.3     31.2     12.48     4.3056]
 [340.      26.5     31.1     12.3778   4.6961]
 [363.      29.      33.5     12.73     4.4555]
 [430.      29.      34.      12.444    5.134 ]]
 
fish_target = fish['Species'].to_numpy()
print(fish_target)

['Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream'
 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream'
 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream'
 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Bream' 'Roach'
 'Roach' 'Roach' 'Roach' 'Roach' 'Roach' 'Roach' 'Roach' 'Roach' 'Roach'
 'Roach' 'Roach' 'Roach' 'Roach' 'Roach' 'Roach' 'Roach' 'Roach' 'Roach'

Train, Test Set์„ ์ค€๋น„ํ•ฉ๋‹ˆ๋‹ค.

from sklearn.model_selection import train_test_split

train_input, test_input, train_target, test_target = train_test_split(
    fish_input, fish_target, random_state=42)

StandardScaler์„ ์ด์šฉํ•˜์—ฌ ์ •๊ทœํ™”๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

from sklearn.preprocessing import StandardScaler

ss = StandardScaler()
ss.fit(train_input)
train_scaled = ss.transform(train_input)
test_scaled = ss.transform(test_input)

K ์ตœ๊ทผ์ ‘ ๋ถ„๋ฅ˜

Logistic regression๊ณผ ๋น„๊ตํ•˜๊ธฐ ์œ„ํ•˜์—ฌ K ์ตœ๊ทผ์ ‘ ๋ถ„๋ฅ˜๋ฅผ ์ˆ˜ํ–‰ํ•ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

from sklearn.neighbors import KNeighborsClassifier

kn = KNeighborsClassifier(n_neighbors=3)
kn.fit(train_scaled, train_target)

print(kn.score(train_scaled, train_target))
print(kn.score(test_scaled, test_target))

0.8907563025210085
0.85

์ด์ง„ Logistric Regression

์ด์ง„๋ถ„๋ฅ˜์—์„œ๋Š” ํ‘œ์ค€์ ์ˆ˜(z)์„ ํ™•์œจ๋กœ ๋ฐ”๊พธ๊ธฐ ์œ„ํ•˜์—ฌ Sigmoid ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๋ฐ์ดํ„ฐ๋ฅผ ์ค€๋น„ํ•˜๊ณ , ์ด์ง„ ๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

bream_smelt_indexes = (train_target == 'Bream') | (train_target == 'Smelt')
train_bream_smelt = train_scaled[bream_smelt_indexes]
target_bream_smelt = train_target[bream_smelt_indexes]

from sklearn.linear_model import LogisticRegression

lr = LogisticRegression()
lr.fit(train_bream_smelt, target_bream_smelt)

print(kn.score(train_bream_smelt, target_bream_smelt))
0.9696969696969697

์•„๋ž˜์™€ ๊ฐ™์ด ๋ถ„๋ฅ˜ ํ•ญ๋ชฉ์„ classes๋กœ ํ™•์ธํ•˜๊ณ , ๊ณ„์ˆ˜(coeffcient)๋“ค๊ณผ ์ ˆํŽธ(intercept)์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋•Œ, Bream, Smelt์˜ ๊ณ„์‚ฐ๋œ ๊ฐ’์„ proba๋กœ ์ฐ์–ด๋ณด๋ฉด 0-1์˜ ํ™•๋ฅ ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ๊ณ„์‚ฐ๋จ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ‘œ์ค€์ ์ˆ˜(z)๋Š” "z = a * Weight + b * Length + c * Diagonal + d * Height + e * Width + f"๋กœ ํ‘œํ˜„๋˜๋ฏ€๋กœ, ์ด๋•Œ a, b, c, d, e๋Š” "lr.coef_"๋กœ ์ ์šฉ๋จ์„ ์•„๋ž˜์™€ ๊ฐ™์ด ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

print(lr.classes_)
print(lr.coef_, lr.intercept_)
print(lr.predict(train_bream_smelt[:5]))
print(lr.predict_proba(train_bream_smelt[:5]))

['Bream' 'Smelt']
[[-0.4037798  -0.57620209 -0.66280298 -1.01290277 -0.73168947]] [-2.16155132]
['Bream' 'Smelt' 'Bream' 'Bream' 'Bream']
[[0.99759855 0.00240145]
 [0.02735183 0.97264817]
 [0.99486072 0.00513928]
 [0.98584202 0.01415798]
 [0.99767269 0.00232731]]

ํ‘œ์ค€์ ์ˆ˜๋ฅผ decision_function์œผ๋กœ ๊ตฌํ•˜๊ณ , ์ด๋ฅผ Sigmoid ํ•จ์ˆ˜์— ํ•ด๋‹นํ•˜๋Š” expit()๋กœ ๊ตฌํ•˜๋ฉด, ์ƒ๊ธฐ์˜ ํ™•์œจ๊ณผ ๊ฐ™์€ ๊ฐ’์ž„์„ ์•Œ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

decisions = lr.decision_function(train_bream_smelt[:5])
print(decisions)

from scipy.special import expit
print(expit(decisions))

[-6.02927744  3.57123907 -5.26568906 -4.24321775 -6.0607117 ]
[0.00240145 0.97264817 0.00513928 0.01415798 0.00232731]

๋‹ค์ค‘ Logistic Regression

ํ‘œ์ค€์ ์ˆ˜(z)์„ ํ™•์œจ๋กœ ๋ฐ”๊พธ๊ธฐ ์œ„ํ•˜์—ฌ Softmax ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์ค‘๋ถ„๋ฅ˜๋ฅผ ์“ฐ๋Š” ๋กœ์ง€์Šคํ‹ฑ ํšŒ๊ท€์—์„œ๋Š” C๋ฅผ ์ด์šฉํ•ด ๊ทœ์ œ (L2 ๊ทœ์ œ๋ฅผ ๊ธฐ๋ณธ์ ์šฉ)๋ฅผ ํ•˜๋Š”๋ฐ, C ๊ฐ’์ด ํด์ˆ˜๋ก ๊ทœ์ œ๊ฐ€ ์•ฝํ•ด์ง‘๋‹ˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ๋‹ค์ค‘๋ถ„๋ฅ˜๋กœ Logistric regression์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. K ์ตœ๊ทผ์ ‘ ๋ถ„๋ฅ˜๋ณด๋‹ค ์ข‹์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

lr = LogisticRegression(C=20, max_iter=1000)
lr.fit(train_scaled, train_target)

print(lr.score(train_scaled, train_target))
print(lr.score(test_scaled, test_target))

0.9327731092436975
0.925

์ด๋•Œ ๋‚ด๋ถ€์—์„œ ๊ฒŒ์‚ฐ๋œ ๊ฐ’์„ ์•„๋ž˜์™€ ๊ฐ™์ด predict์™€ predict_proba๋กœ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

print(lr.classes_)
print(lr.coef_.shape, lr.intercept_.shape)

proba = lr.predict_proba(test_scaled[:5])

import numpy as np
print(np.round(proba, decimals=3))

['Bream' 'Parkki' 'Perch' 'Pike' 'Roach' 'Smelt' 'Whitefish']
(7, 5) (7,)
[[0.    0.014 0.841 0.    0.136 0.007 0.003]
 [0.    0.003 0.044 0.    0.007 0.946 0.   ]
 [0.    0.    0.034 0.935 0.015 0.016 0.   ]
 [0.011 0.034 0.306 0.007 0.567 0.    0.076]
 [0.    0.    0.904 0.002 0.089 0.002 0.001]]

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํ‘œ์ค€์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•˜๊ณ , Softmax๋กœ ํ™•์œจ์„ ๊ณ„์‚ฐํ•˜๋ฉด predict_proba๋กœ ์–ป์–ด์ง„ ๊ฒฐ๊ณผ์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

decision = lr.decision_function(test_scaled[:5])
print(np.round(decision, decimals=2))

from scipy.special import softmax

proba = softmax(decision, axis=1)
print(np.round(proba, decimals=3))

[[ -6.5    1.03   5.16  -2.73   3.34   0.33  -0.63]
 [-10.86   1.93   4.77  -2.4    2.98   7.84  -4.26]
 [ -4.34  -6.23   3.17   6.49   2.36   2.42  -3.87]
 [ -0.68   0.45   2.65  -1.19   3.26  -5.75   1.26]
 [ -6.4   -1.99   5.82  -0.11   3.5   -0.11  -0.71]]
 
[[0.    0.014 0.841 0.    0.136 0.007 0.003]
 [0.    0.003 0.044 0.    0.007 0.946 0.   ]
 [0.    0.    0.034 0.935 0.015 0.016 0.   ]
 [0.011 0.034 0.306 0.007 0.567 0.    0.076]
 [0.    0.    0.904 0.002 0.089 0.002 0.001]]

SGDClassifier

ํ™•๋ฅ ์  ๊ฒฝ์‚ฌํ•˜๊ฐ•๋ฒ•(SGD, Stochastic Gradient Descent)์„ ์ด์šฉํ•˜์—ฌ ์„ ํ˜•๋ชจ๋ธ๋กœ Linear classifiers์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. SGDClassifier.ipynb์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

from sklearn.model_selection import cross_validate
from sklearn.linear_model import SGDClassifier

sc = SGDClassifier(loss='log', max_iter=5, random_state=42)

scores = cross_validate(sc, train_scaled, train_target, n_jobs=-1)

import numpy as np
print(np.mean(scores['test_score']))

์ƒ๊ธฐ์˜ sample ์‚ฌ์šฉ์‹œ 3 class๊ฐ€ n_splits๋ณด๋‹ค ์ž‘์œผ๋ฏ€๋กœ ๊ฒฐ๊ณผ๋Š” ์ข‹์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

/home/ec2-user/anaconda3/envs/python3/lib/python3.8/site-packages/sklearn/model_selection/_split.py:676: UserWarning: The least populated class in y has only 3 members, which is less than n_splits=5.
  warnings.warn(

0.7144927536231884

Low Accuracy Case

Logistic Regression ์ ์šฉ์‹œ์— ์ •ํ™•๋„๊ฐ€ ๋–จ์–ด์ง€๋Š” ์ผ€์ด์Šค์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

  1. ๋ฐ์ดํ„ฐ๋ฅผ ์ค€๋น„ํ•ฉ๋‹ˆ๋‹ค.

pandas๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

import pandas as pd

wine = pd.read_csv('https://bit.ly/wine_csv_data')

wine.head()

์ด๋•Œ ๋ฐ์ดํ„ฐ์˜ ํ˜•ํƒœ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด "alcohol", "sugar", "pH"์™€ ๊ฐ™์€ ํ•ญ๋ชฉ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

image

์—ฌ๊ธฐ์˜ ๋ฐ์ดํ„ฐ์˜ ํ˜•ํƒœ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

wine.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 6497 entries, 0 to 6496
Data columns (total 4 columns):
 #   Column   Non-Null Count  Dtype  
---  ------   --------------  -----  
 0   alcohol  6497 non-null   float64
 1   sugar    6497 non-null   float64
 2   pH       6497 non-null   float64
 3   class    6497 non-null   float64
dtypes: float64(4)
memory usage: 203.2 KB

Train, Test Set์„ ์•„๋ž˜์™€ ๊ฐ™์ด ์ค€๋น„ํ•ฉ๋‹ˆ๋‹ค.

data = wine[['alcohol', 'sugar', 'pH']].to_numpy()
target = wine['class'].to_numpy()

from sklearn.model_selection import train_test_split

train_input, test_input, train_target, test_target = train_test_split(
    data, target, test_size=0.2, random_state=42)

print(train_input.shape, test_input.shape)
(5197, 3) (1300, 3)

์•„๋ž˜์™€ ๊ฐ™์ด ์ •๊ทœํ™”๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

from sklearn.preprocessing import StandardScaler

ss = StandardScaler()
ss.fit(train_input)

train_scaled = ss.transform(train_input)
test_scaled = ss.transform(test_input)
  1. Logistic Regression์œผ๋กœ ๊ฒฐ์ •๊ณ„์ˆ˜๋ฅผ ๊ตฌํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜์™€ ๊ฐ™์ด ๊ณผ์†Œ์ ํ•ฉ(Underfitting)์˜ ๊ฒฐ๊ณผ๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค.

from sklearn.linear_model import LogisticRegression

lr = LogisticRegression()
lr.fit(train_scaled, train_target)

print(lr.score(train_scaled, train_target))
print(lr.score(test_scaled, test_target))

0.7808350971714451
0.7776923076923077

์ด๋•Œ, "alcohol", "sugar", "pH"์— ๋Œ€ํ•œ ๊ธฐ์šธ๊ธฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

print(lr.coef_, lr.intercept_)

[[ 0.51270274  1.6733911  -0.68767781]] [1.81777902]

Reference

ํ˜ผ์ž ๊ณต๋ถ€ํ•˜๋Š” ๋จธ์‹ ๋Ÿฌ๋‹+๋”ฅ๋Ÿฌ๋‹

sklearn.linear_model.SGDClassifier

[Machine Learning at Work - ํ•œ๋น›๋ฏธ๋””์–ด]

Using Machine Learning to Predict Parking Difficulty

Understanding Logistic Regression in Python Tutorial