리스트 끼리 곱
import numpy as np
x_input=np.array([1,2,3,4,5,6,7,8,9,10],dtype = np.float32)
labels = np.array([3,5,7,9,11,13,15,17,19,21],dtype = np.float32) #
W,B = np.random.normal(size=1,), np.random.normal(size=1,)
def Hypothesis(x):
return W*x +B
def Cost() :
return np.mean((Hypothesis(x_input)-labels)**2)
def Gradient(x,y):
return np.mean(x*(x+W+(B-y))), np.mean((W*x -y +B))
epochs = 5000
learning_rate = 0.005
for cnt in range(0, epochs+1) :
if cnt % (epochs//20) ==0:
print("[{}]cost={},W={}, B={}".format(cnt,Cost(),W,B))
grad_W, grad_B = Gradient(x_input,labels)
W -= learning_rate * grad_W
B -= learning_rate * grad_B
함수 보면 가능.
'Tensorflow' 카테고리의 다른 글
Multi variable Linear Regression (Numpy) (1) | 2023.12.27 |
---|---|
Tf Linear regression (1차) (0) | 2023.12.27 |
keras 경사하강 기초. (0) | 2023.12.26 |
경사하강법 (0) | 2023.12.26 |
TypeError: integer argument expected, got float (0) | 2023.12.26 |