"Sklearn 단순회귀분석"의 두 판 사이의 차이

29번째 줄: 29번째 줄:
print( df )
print( df )


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


from sklearn import linear_model
from sklearn.linear_model import LinearRegression
reg = linear_model.LinearRegression()
reg = LinearRegression().fit(X, y)
reg.fit(X,Y)
print( "coefficient=", reg.coef_ )
print( "coefficient=", reg.coef_ )
print( "intercept=", reg.intercept_ )
print( "intercept=", reg.intercept_ )
print( "R²=", reg.score(X,Y) )
print( "R²=", reg.score(X, y) )
</source>
</source>



2020년 4월 3일 (금) 00:25 판

1 개요

sklearn 단순선형회귀분석

2 예시 1: mass ~ height

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.loc[:,['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: order ~ high_temperature

import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/jmnote/z-dataset/master/simple-regression/Norns-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) )

4 같이 보기

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