Sklearn 단순회귀분석

(Sklearn 단순선형회귀에서 넘어옴)

1 개요[ | ]

sklearn 단순선형회귀분석

2 예시 1: 키와 몸무게[ | ]

import pandas as pd
df = pd.DataFrame({
'height': [1.47, 1.50, 1.52, 1.55, 1.57, 1.60, 1.63, 1.65, 1.68, 1.70, 1.73, 1.75, 1.78, 1.80, 1.83],
'mass': [52.21, 53.12, 54.48, 55.84, 57.20, 58.57, 59.93, 61.29, 63.11, 64.47, 66.28, 68.10, 69.92, 72.19, 74.46],
})

X = df[['height']]
Y = df['mass']

from sklearn import linear_model
reg = linear_model.LinearRegression()
reg.fit(X, Y)
print( "coefficient=", reg.coef_ )
print( "intercept=", reg.intercept_ )
print( "R²=", reg.score(X, Y) )
→ 회귀식 [math]\displaystyle{ y=61.27218654x-39.06195591884392 }[/math]
→ 결정계수 [math]\displaystyle{ R^2=0.9891969224457968 }[/math]

3 예시 2: 아이스티 주문[ | ]

import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/jmnote/z-dataset/master/simple-regression/iced-tea-orders.csv')
print( df )

X = df[['high_temperature']]
Y = df['order']

from sklearn.linear_model import LinearRegression
reg = LinearRegression().fit(X, Y)
print( "coefficient=", reg.coef_ )
print( "intercept=", reg.intercept_ )
print( "R²=", reg.score(X, Y) )
→ 회귀식 [math]\displaystyle{ y=3.73788546x-36.361233480176196 }[/math]
→ 결정계수 [math]\displaystyle{ R^2=0.8225092881166944 }[/math]

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}