๋ฌธ์
**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๋ฅผ ์ ๋ถ ์ธ์์ผํจ ใ ใ