DBILITY

독거 가능성 100% 노후에 라면값이라도 하게 센스를 발휘합시다!😅
Please click on the ad so that I can pay for ramen in my old age!
点击一下广告,让老后吃个泡面钱吧!
老後にラーメン代だけでもするように広告を一回クリックしてください。

python matplot scatter chart , linear regression line exercise 본문

python

python matplot scatter chart , linear regression line exercise

DBILITY 2021. 10. 13. 14:00
반응형

독거 가능성 100% 노후에 라면값이라도 하게 광고 한번씩 클릭하시오!

Please click on the ad so that I can pay for ramen in my old age!
老後にラーメン代だけでもするように広告を一回クリックしてください。
点击一下广告,让老后吃个泡面钱吧!

선형회귀에 대한 학습은 언젠가 해야겠다.

https://ko.wikipedia.org/wiki/%EC%84%A0%ED%98%95_%ED%9A%8C%EA%B7%80

 

선형 회귀 - 위키백과, 우리 모두의 백과사전

독립변수 1개와 종속변수 1개를 가진 선형 회귀의 예 통계학에서, 선형 회귀(線型回歸, 영어: linear regression)는 종속 변수 y와 한 개 이상의 독립 변수 (또는 설명 변수) X와의 선형 상관 관계를 모

ko.wikipedia.org

최소제곱법

https://ko.wikipedia.org/wiki/%EC%B5%9C%EC%86%8C%EC%A0%9C%EA%B3%B1%EB%B2%95

 

최소제곱법 - 위키백과, 우리 모두의 백과사전

붉은 점들을 기반으로 푸른 선의 2차 방정식 근사해를 구한다. 최소제곱법, 또는 최소자승법, 최소제곱근사법, 최소자승근사법(method of least squares, least squares approximation)은 어떤 계의 해방정식을

ko.wikipedia.org

sklearn 미설치 시 설치 ( pip install -U scikit-learn )

수학시간에 산점도 또는 산포도라고 배웠던 그것이다.

import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
import numpy as np

heights = [170, 180, 160, 165, 205]
weights = [75, 89, 50, 60, 110]
nheights = np.array(heights).reshape((-1, 1))
nweights = np.array(weights).reshape((-1, 1))

model = LinearRegression().fit(nheights, nweights)
#print(model.score(nheights, nweights))
#print(model.intercept_)
#print(model.coef_)
r = model.predict(nheights)
#print(r)

plt.text(x=182, y=80, s='hyperrookie@gmail.com', rotation=0, color='whitesmoke', horizontalalignment='center', verticalalignment='center',
         fontsize=22, fontweight='bold')
plt.title('scatter plot')
plt.xlabel('height')
plt.ylabel('weight')

plt.scatter(heights, weights)
plt.plot(heights, r, color='red', linewidth=1)
plt.show()

결과는 그림 1과 같다.

그림1

반응형

'python' 카테고리의 다른 글

python pandas dataframe  (0) 2021.10.12
python papago translate api example  (0) 2021.10.12
python matplot pie chart  (0) 2021.08.30
python matplot bar chart example  (0) 2021.08.27
python matplot line chart example  (0) 2021.08.25
Comments