일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |
Tags
- ML
- 관리
- server
- 선형회귀
- Machine Learning
- TensorFlow
- 설정
- 설치
- centOS
- vuejs
- 머신러닝
- Visual Intelligence
- linux
- xshell
- python 설치
- Network
- Python
- vmware
- 운영체제
- 칼리
- 리눅스
- 텐서플로우
- 가상머신
- Language Intelligence
- 시퀸스 자료형
- representation learning
- Python 기초
- Windows
- vue
- Kali
Archives
- Today
- Total
homebody's blog
[Python][TensorFlow] 03. 선형회귀 TensorFlow로 구현 본문
TensorFlow(Simple Linear Regression을TensorFlow로 구현)
x_data = [1,2,3,4,5]
y_data = [1,2,3,4,5]
W = tf.Variable(2.9)
b = tf.Variable(0.5)
# hypothesis = W * x + b
hypothesis = W * x_data + b
cost = tf.reduce_mean(tf.square(hypothesis - y_data))
-
Cost가 최소가 되는 W, b를 찾는 알고리즘
-
Gradient descent(경사하강알고리즘 or 경사하강법)
# Learning_rate initialize learning_rate = 0.01 # Gradient descent with tf.GradientTape() as tape: hypothesis = W * x_data + b cost = tf.reduce_mean(tf.square(hypothesis - y_data)) W_grad, b_grad = tape.gradient(cost, [W, b]) W.assign_sub(learning_rate * W_grad) b.assign_sub(learning_rate * b_grad)
-
Gradient descent 전체 코드(경사하강알고리즘 or 경사하강법)
import tensorflow as tf tf.enable_eager_execution() # Data x_data = [1,2,3,4,5] y_data = [1,2,3,4,5] # W, b initialize W = tf.Variable(2.9) b = tf.Variable(0.5) learning_rate = 0.01 for i in range(100+1): # W, b update # Gradient descent with tf.GradientTape() as tape: hypothesis = W * x_data + b cost = tf.reduce_mean(tf.square(hypothesis - y_data)) W_grad, b_grad = tape.gradient(cost, [W, b]) W.assign_sub(learning_rate * W_grad) b.assign_sub(learning_rate * b_grad) if i % 10 == 0: print("{:5}|{:10.4f}|{:10.4}|{:10.6f}".format(i, W.numpy(), b.numpy(), cost))
-
'Python > TensorFlow' 카테고리의 다른 글
[Python][TensorFlow] 06. 다중 선형 회귀 TensorFlow 구현(Multi-variable Linear Regression) (0) | 2019.06.22 |
---|---|
[Python][TensorFlow] 05. 다중 선형 회귀(Multi-variable Linear Regression) (0) | 2019.06.21 |
[Python][TensorFlow] 04. 선형회귀와 비용을 최소화 하는 방법 (0) | 2019.06.19 |
[Python][TensorFlow] 02. 간단한 선형 회귀(Simple Linear Regression) (0) | 2019.06.18 |
[Python][TensorFlow] 01. basic ML의 용어와 개념 설명 (0) | 2019.06.18 |
Comments