반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 자료구조
- 결합전문기관
- vscode
- paragraph
- 재귀함수
- inorder
- web 용어
- KNeighborsClassifier
- web 개발
- CES 2O21 참가
- pycharm
- cudnn
- html
- web 사진
- postorder
- broscoding
- 머신러닝
- tensorflow
- Keras
- classification
- CES 2O21 참여
- bccard
- mglearn
- 대이터
- 데이터전문기관
- web
- java역사
- discrete_scatter
- C언어
- 웹 용어
Archives
- Today
- Total
bro's coding
sklearn.linear regression.꽃종류 별 회귀 선 그리기 본문
반응형
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
# data 수집
iris=load_iris()
# column 컨트롤
col1=2
col2=3
# 전체 data에 대한 scatterplot graph
plt.scatter(iris.data[:,col1],iris.data[:,col2],c=iris.target,alpha=0.7)
X=iris.data[:,[col1]]
# 주의 : col1->[col1]
y=iris.data[:,col2]
# LinearRegression
model = LinearRegression()
# train
model.fit(X,y)
#predict
pred_y=model.predict(X)
# 선에 대한 x 범위 산출
xxx=np.array([X.min()-0.5,X.max()+0.5])
# 1차 방정식
yyy=model.coef_*xxx+model.intercept_
# 기울기 : w(weight)=coef_ ,절편 : b(ax+b)=intercept_
# 1차 방정식 graph
plt.plot(xxx,yyy,'b:',label='all')
#전체 데이터에 대한 평가지표
MSE=((y-pred_y)**2).mean()
RMSE=np.sqrt(MSE)
MAE=np.abs(y-pred_y).mean()
print(MSE,RMSE,MAE,model.score(X,y))
# 0.04228994631948424 0.20564519522586527 0.1572565947049201 0.9269012279220037
for i in range(3):
X=iris.data[50*i:50*(i+1),[col1]]
y=iris.data[50*i:50*(i+1),col2]
# print([50*i,50*(i+1)])
# [0, 50]
# [50, 100]
# [100, 150]
model = LinearRegression()
model.fit(X,y)
xxx=np.array([X.min()-0.5,X.max()+0.5])
yyy=model.coef_*xxx+model.intercept_
# 기울기 : w(weight)=coef_ ,절편 : b(ax+b)=intercept_
plt.plot(xxx,yyy,':',label=iris.target_names[i])
plt.legend()
반응형
'[AI] > python.sklearn' 카테고리의 다른 글
sklearn.sigmoid function (0) | 2020.04.13 |
---|---|
sklearn.linear_model.LogisticRegression(로지스틱 회귀) (0) | 2020.04.13 |
sklearn.datasets .make_blobs 사용하기 (0) | 2020.04.13 |
sklearn.linear regression.다차원(wine)등급 예상하기(정규화) (0) | 2020.04.10 |
sklearn.linear regression 회귀 선 그리기 (0) | 2020.04.09 |
sklearn.linearRegression. basic (0) | 2020.04.09 |
sklearn.영향력 없는 column 찾기(knn) (0) | 2020.04.09 |
sklearn.matplotlib로 knn표현하기 (0) | 2020.04.09 |
Comments