Simple Linear Regression #3

올림픽 높이 뛰기 표. Numpy의 regression 함수를 적용해보도록 한다.

YearHeight(m)YearHeight(m)
19003.3019564.56
19043.5019604.70
19083.7119645.10
19123.9519685.40
19204.0919725.50
19243.9519765.50
19284.2019805.78
19324.3119845.75
19364.3519885.90
19484.3019925.80
19524.5519965.92
(a) Make a scatter plot and decide whether a linear model in appropriate
(b) Find and graph the regression line

Least square regression이 SciPy에 포함된 줄 알았더니 그냥 NumPy에 이미 있었다. ^^;

#using lstsq method from numpy
 A = vstack ( [ year, ones (len (year) ) ] ).T
 m_l , c_l = linalg.lstsq (A, height) [0]
 print m_l, c_l

아래 그림에서 녹색은 least square regression 방식이고 붉은색 라인은 first/last point를 이용한 regression이다.

 
 

댓글 달기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

위로 스크롤