1 개요[ | ]
- statsmodels 단순회귀분석
- statsmodels 단순선형회귀분석
2 예시 1: Y ~ X[ | ]
Python
CPU
1.8s
MEM
115M
1.5s
Copy
import statsmodels.api as sm
Y = [1,3,4,5,2,3,4]
X = [1,2,3,4,5,6,7]
X = sm.add_constant(X)
model = sm.OLS(Y,X)
results = model.fit()
print( results.params )
print( "R²=", results.rsquared )
[2.14285714 0.25 ] R²= 0.16118421052631615
- → 회귀식 [math]\displaystyle{ y=0.25x+2.14285714 }[/math]
- → 결정계수 [math]\displaystyle{ R^2=0.16118421052631593 }[/math]
3 예시 2: 키와 몸무게[ | ]
Python
Reload
Copy
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],
})
Y = df['mass']
X = df['height']
Loading
- → 회귀식 [math]\displaystyle{ y=61.272187x-39.061956 }[/math]
Copy
results.rsquared
Loading
- → 결정계수 [math]\displaystyle{ R^2=0.9891969224457968 }[/math]
4 예시 3: 아이스티 주문[ | ]
- → 회귀식 [math]\displaystyle{ y=3.737885x-36.361233 }[/math]
- → 결정계수 [math]\displaystyle{ R^2=0.8225092881166943 }[/math]
5 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.