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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 22개는 보이지 않습니다)
2번째 줄: 2번째 줄:
;sklearn 단순선형회귀분석
;sklearn 단순선형회귀분석


<source lang='python'>
==예시 1: 키와 몸무게==
<syntaxhighlight lang='python' run>
import pandas as pd
import pandas as pd
df = pd.DataFrame({
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],
'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],
'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']
X = df[['height']]
Y = df['mass']


from sklearn import linear_model
from sklearn import linear_model
reg = linear_model.LinearRegression()
reg = linear_model.LinearRegression()
reg.fit(X,y)
reg.fit(X, Y)
print( "R²=", reg.score(X,y) )
print( "coefficient=", reg.coef_ )
print( "intercept=", reg.intercept_ )
print( "R²=", reg.score(X, Y) )
</syntaxhighlight>
:→ 회귀식 <math>y=61.27218654x-39.06195591884392</math>
:→ 결정계수 <math>R^2=0.9891969224457968</math>
 
==예시 2: 아이스티 주문==
<syntaxhighlight lang='python' run>
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( "coefficient=", reg.coef_ )
print( "intercept=", reg.intercept_ )
print( "intercept=", reg.intercept_ )
# R²= 0.989196922446
print( "R²=", reg.score(X, Y) )
# coefficient= [ 61.27218654]
</syntaxhighlight>
# intercept= -39.0619559188
:→ 회귀식 <math>y=3.73788546x-36.361233480176196</math>
</source>
:→ 결정계수 <math>R^2=0.8225092881166944</math>


==같이 보기==
==같이 보기==
* [[statsmodels 단순선형회귀분석]]
* [[단순회귀분석]]
* [[TensorFlow 단순선형회귀분석]]
* [[R 단순회귀분석]]
* [[단순선형회귀분석]]
* [[Sklearn 다중회귀분석]]
* [[statsmodels 단순회귀분석]]
* [[TensorFlow 단순회귀분석]]


[[분류: sklearn]]
[[분류: sklearn 회귀분석]]
[[분류: 회귀분석]]
[[분류: Python 데이터 분석]]
[[분류: Python 데이터 분석]]

2020년 11월 2일 (월) 00:56 기준 최신판

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 }}