반응형
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
- pycharm
- Keras
- CES 2O21 참가
- 머신러닝
- inorder
- 대이터
- vscode
- 결합전문기관
- web 용어
- bccard
- C언어
- 데이터전문기관
- KNeighborsClassifier
- paragraph
- java역사
- discrete_scatter
- web 개발
- 웹 용어
- broscoding
- classification
- cudnn
- html
- postorder
- tensorflow
- mglearn
- web 사진
- web
- CES 2O21 참여
- 재귀함수
- 자료구조
Archives
- Today
- Total
bro's coding
경사하강법 본문
반응형
import numpy as np
from sklearn.datasets import load_iris
# data 준비
iris=load_iris()
x = iris.data[:,2]
y = iris.data[:,3]
# 초기화
w = np.random.randn()/10
b = np.random.randn()/10
# learning rate 설정
lr = 0.05
pred_y = x*w + b
mse = np.mean((y-pred_y)**2)
costs = [mse]
for i in range(3000):
pred_y = x*w + b
dw = lr*2/len(y)*np.sum((y-pred_y)*x)
db = lr*2/len(y)*np.sum(y-pred_y)
w_new = w + dw
b_new = b + db
mse_new = np.mean((y-(x*w_new + b_new))**2)
# 종료점
if mse_new>=mse: break
w = w_new
b = b_new
mse = mse_new
costs.append(mse)
print(i, w, b, mse)
881 0.4164191208275526 -0.3665139932459091 0.04228994631948473
plt.plot(costs[:100])
(array([0.41641913]), -0.3665140452167275)
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(x.reshape(-1,1), y)
model.coef_, model.intercept_
반응형
'[AI] > python.Neural_Network' 카테고리의 다른 글
다중 분류 원리 (0) | 2020.05.08 |
---|---|
중간층 만들기(분류) (0) | 2020.05.07 |
중간층 만들기(값예측) (0) | 2020.05.07 |
activation function(활성 함수) (0) | 2020.05.07 |
neural_network.logisticRegression.원리알기 (0) | 2020.05.06 |
Comments