๐Ÿ† ์ž๊ฒฉ์ฆ, ์–ดํ•™

[๋น…๋ฐ์ดํ„ฐ ๋ถ„์„๊ธฐ์‚ฌ] ์‹ค๊ธฐ 6ํšŒ - 3์œ ํ˜• predict

๋ฐ์ดํ„ฐํŒ์Šค 2024. 8. 21. 18:04

 

๋ฌธ์ œ

**age๊ฐ€ 55, Cholesterol๊ฐ€ 72.6์ผ๋•Œ ์œ„ ๋ชจ๋ธ์„ ๊ธฐ๋ฐ˜์œผ๋กœ weight๊ฐ’์„ ์˜ˆ์ธกํ•˜๋ผ.**

 

import pandas as pd
import numpy as np
import statsmodels.api as sm

x=df[['age','Cholesterol']]
y=df['weight']

x=sm.add_constant(x)
model=sm.OLS(y,x).fit()
pred = model.predict([1,55,72.6]) # const , age,Cholesterol
print(pred)
 
 

statsmodel ๋ฐฉ์‹์œผ๋กœ ํ’€์—ˆ์„ ๋•Œ๋Š” model.preict() ๋˜๋Š” model.pvalues()๊ฐ€ ๋œ๋‹ค

๊ฐ’์€ 78.8577101134459

x=df[['age','Cholesterol']]
y=df['weight']
from sklearn.linear_model import LinearRegression
model=LinearRegression()
re=model.fit(x,y)
pred = re.predict([1,55,72.6]) # const , age,Cholesterol
model.coef_
 

๊ทผ๋ฐ sklearn์œผ๋กœ ํ’€์—ˆ์„ ๋•Œ๋Š” ์ €๊ฒŒ ๋œ๋‹ค 1์ด const๋ฅผ ์˜๋ฏธํ•˜๋Š” ๊ฑด๊ฐ€๋ด„..

์ง์ ‘ ํšŒ๊ท€์‹ ๊ตฌํ•ด์„œ๋„ ๋„ฃ์–ด๋ดค๋Š”๋ฐ

sum=74.8953-0.0361*55+0.0819*72.6
print(sum)
 

78.85574๊ฐ€ ๋‚˜์™”๋‹ค...

 

๊ฒฐ๊ตญ์—” sklearn๊ณผ statsmodels๋ฅผ ์ „๋ถ€ ์™ธ์›Œ์•ผํ•จ ใ… ใ