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
- RED CAT COFFEE X LOUNGE
- 냥스토리
- 스코티쉬 스트레이트
- 커플
- 발산역 근처 카페
- 스테이크
- 소호정본점
- 소호정
- 안동국시
- CDJ
- 냥냥
- 발산
- 냥이
- 카페
- 고양이는 언제나 귀엽다
- 양재맛집
- 데이트
- 파버스
- A. Steed 2: Cruise Control
- CodeJam 2017 Round 1B
- 파머스테이블
- 치명적 귀여움
- codejam
- 스파게티
- 먹기좋은곳
- 레스토랑
- 발산맛집
- 고양이
- 부모님과
- coffee
Archives
- Today
- Total
hubring
Linear Regression 본문
[참고] 모두를 위한 딥러닝 - 기본적인 머신러닝과 딥러닝 강좌
Regression (DATA)
x | y |
---|---|
1 | 1 |
2 | 2 |
3 | 3 |
(Linear) Hypothesis
- 선형식을 찾는 과정
- 가설 식 :
H(x) = Wx + b
- 어떤 식이 좋은 가?
- 가설과 실제 데이터를 거리를 비교하여 오차가 적은것.
=> cost function
=> H(x) - y
Cost function
Goal : minimize cost
- minimize cost(W, b)
tensorflow 구현 (Variable 이용)
import numpy as np
import tensorflow.compat.v1 as tf
import matplotlib.pyplot as plt
tf.disable_v2_behavior()
x_train = [1, 2, 3]
y_train = [1, 2, 3]
W = tf.Variable(tf.random_normal([1]), name='weight')
b = tf.Variable(tf.random_normal([1]), name='bias')
hypotheis = x_train * W + b
cost = tf.reduce_mean(tf.square(hypotheis - y_train))
optimizer = tf.train.GradientDescentOptimizer(learning_rate = 0.01)
train = optimizer.minimize(cost)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
for step in range(2001) :
sess.run(train)
if step % 20 == 0 :
print(step, sess.run(cost), sess.run(W), sess.run(b))
tensorflow 구현 (Placeholder 이용)
import numpy as np
import tensorflow.compat.v1 as tf
import matplotlib.pyplot as plt
tf.disable_v2_behavior()
X = tf.placeholder(tf.float32, shape=[None])
Y = tf.placeholder(tf.float32, shape=[None])
W = tf.Variable(tf.random_normal([1]), name='weight')
b = tf.Variable(tf.random_normal([1]), name='bias')
hypotheis = X * W + b
cost = tf.reduce_mean(tf.square(hypotheis - Y))
optimizer = tf.train.GradientDescentOptimizer(learning_rate = 0.01)
train = optimizer.minimize(cost)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
for step in range(2001) :
cost_val, W_val, b_val, _ = sess.run([cost, W, b, train], feed_dict={X:[1, 2, 3, 4, 5], Y:[2.1, 3.1, 4.1, 5.1, 6.1]})
if step % 20 == 0 :
print(step, cost_val, W_val, b_val)
'AI > Tensorflow' 카테고리의 다른 글
TensorFlow로 파일에서 데이터 읽어오기 (0) | 2021.03.05 |
---|---|
Multi-variable linear regression (0) | 2021.02.24 |
Linear Regression의 cost 최소화 원리 (0) | 2021.02.23 |
머신 러닝 기본 (0) | 2021.02.23 |
k-인접이웃 분류모형 (0) | 2019.09.18 |