Linear regression

์„ ํ˜•ํšŒ๊ท€

Linear regression

  • ๋น„๊ต์  ๊ฐ„๋‹จํ•˜๊ณ  ์„ฑ๋Šฅ์ด ๋›ฐ์–ด๋‚จ
  • ํŠน์„ฑ์ด ํ•˜๋‚˜์ธ ๊ฒฝ์šฐ ์–ด๋–ค ์ง์„ ์„ ํ•™์Šต
  • ํŠน์„ฑ์˜ ๊ฐœ์ˆ˜๋ฅผ ํฌ๊ฒŒ ๋Š˜๋ฆฌ๋ฉด ์„ ํ˜•๋ชจ๋ธ์ด ๊ฐ•๋ ฅํ•ด์ง. But, ํŠน์„ฑ์ด ๋„ˆ๋ฌด ๋งŽ์œผ๋ฉด training set์—์„œ ๊ณผ๋Œ€์ ํ•ฉ, test set์—์„œ ๊ณผ์†Œ์ ํ•ฉ
# ๊ธฐ๋ณธ ํ˜•ํƒœ
y = ax + b
  • ์ž…๋ ฅ ํŠน์„ฑ์˜ ๊ฐ€์ค‘์น˜ ํ•ฉ๊ณผ ํŽธํ–ฅ(bias or intercept)๋ผ๋Š” ์ƒ์ˆ˜๋ฅผ ๋”ํ•ด ์˜ˆ์ธก์„ ๋งŒ๋“ฆ

์‚ฌ์ดํ‚ท๋Ÿฐ์—์„œ ์„ ํ˜•ํšŒ๊ท€

from sklearn.linear_model import LinearRegression
lr = LinearRegression()

# ํ›ˆ๋ จ
lr.fit(train_input, train_target)

# ์˜ˆ์ธก
lr.predict(new_value)

# LinearRegression ํด๋ž˜์Šค๊ฐ€ ์ฐพ์€ a์™€ b ๊ฐ’์€ ๊ฐ๊ฐ lr.coef_, lr.intercept_์— ์ €์žฅ
print(lr.coef_, lr.intercept_)

# ํ›ˆ๋ จ์„ธํŠธ score
print(lr.score(train_input, train_target))

# ํ…Œ์ŠคํŠธ์„ธํŠธ score
print(lr.score(test_input, test_target))
  • coef_, intercept_๋Š” model parameter
  • ๋ชจ๋ธ ๊ธฐ๋ฐ˜ ํ•™์Šต = ์ตœ์ ์˜ ๋ชจ๋ธ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ฐพ๋Š” ๊ฒƒ
  • ์‚ฌ๋ก€ ๊ธฐ๋ฐ˜ ํ•™์Šต = ํ›ˆ๋ จ ์„ธํŠธ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ฒƒ์ด ํ›ˆ๋ จ์˜ ์ „๋ถ€. ๋ชจ๋ธ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์—†์Œ

์„ ํ˜•ํšŒ๊ท€



Linear regression์˜ ์„ฑ๋Šฅ ์ธก์ •

  • ํ‰๊ท  ์ œ๊ณฑ๊ทผ ์˜ค์ฐจ (RMSE)
    RMSE
  • RMSE๋ฅผ ์ตœ์†Œํ™”ํ•˜๋Š” ๋ชจ๋ธํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ฐพ์•„์•ผ ํ•จ
  • ์‹ค์ œ๋กœ๋Š” RMSE๋ณด๋‹ค ํ‰๊ท  ์ œ๊ณฑ ์˜ค์ฐจ(MSE)๋ฅผ ์ตœ์†Œํ™”ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ๋‚ด๋ฉด์„œ ๋” ๊ฐ„๋‹จ
    MSE


โ˜… ๋” ๋งŽ์€ ๋‚ด์šฉ ๋ณด๋Ÿฌ๊ฐ€๊ธฐ click click! โ˜