모두를 위한 딥러닝 강의 리뷰(전반부:01-08)

이은비·2024년 3월 5일

"모두를 위한 딥러닝 강의"(아래 강좌 참고)에 대한 내용을 키워드로만 간단히 정리한 것입니다.
https://www.youtube.com/watch?v=GYecDQQwTdI&list=PLlMkM4tgfjnLSOjrEJN31gZATbcj_MpUm&index=25
Lecture 00 강의
supervised-learning : 답이 주어져 있는
unsupervised-learning : 답이 주어져 있지 않은
알파고도 일종의 supervised learning
적용되는 예시들>
점수가 나오는 시험 -> regression
pass/nonpass 시험 -> binary classification
grade가 나오는 시험 -> multi-label classification

Placeholder->미리 값을 초기화 하지 않고 이후에 feed_dict로 할당해서 처리할 수 있다.
Lecture 01 강의
tensorflow에 대한 전반적인 개요
Lecture 01 실습
Placeholder->미리 값을 초기화 하지 않고 이후에 feed_dict로 할당해서 처리할 수 있다.
Lecture 02 강의
Linear regression
x라는 값을 입력으로 주었을 때 나오는 y값 예측(Linear regression)
Linear할 것이라고 가설을 세움.(1차 방정식 형태)
어떤 선이 가장 맞는 선일까를 찾음.
실제값과 예측값 사이의 차이를 계산하는 것이 cost function
주로 오차제곱값을 이용 (-,+고려안하기 위해서)

foraml한 cost function의 식은 실제로는 W,b를 고려한 식.
목표-> cost function을 minimize하는 것.

Lecture 02-2
얼마나 잘 예측을 했는가-> cost function
학습을 한다 cost function의 값을 minimize 한다.
train이란 node 밑에 cost, hy, weight, bias 모두 연결되어 있어서 sess.run(train하면 그 값들이 업데이트 및 print하면 그 값들이 print되는 것을 알 수 있다.)

placeholder란 것으로 값을 주면 미리 초기화 하지 않고 나중에 feed_dict로 값을 전달해 줄 수 있음.
Lecture 02 실습
shape[None] 할당되지 않은 것으로 개수 이상의 것들을 할당 할 수 있다.
Lecture 03 강의
Lecture 03-1
how to minimize cost function?

->Gradient descent algorithm
경사도를 따라 한발자국(alpha값 즉,learning rate를 의미함) 반복.
항상 최저점으로
이때 경사도를 구하는 방법? -> 미분.
alpha는 learning rate. 이때 learning rate는 너무 작아도 문제 너무 커도 문제.
추후에 설명.

추가적으로 convex function이 어떻게 생겼는가 두점을 이었을때 직선일때.
cost function의 모양이 반드시 convex한 모양이어야 한다.

Lecture 03-2
기울기를 구했을때 + ,W 는 -로 (gradient descent)
기울기를 구했을때 - ,W 는 +로
W-gradeint하는 것이니까
gradient항 조정
step이 진행 될 수록 cost는 작아지고 W는 1이 되어가는 것을 알 수 있음.

Lecture 03 실습
#Minimize: gradient descent magic
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.1)
train = optimizer.minimize(cost)

Lecture 04 강의
recap
가설,cost function, gradient descent algorithm
Multi-variable linear regression
implement에서는 matrix multiplication으로 진행된다.

Lecture 04-01
Multi vaariable linear regression
인수로 None->안정해져있다(자유)

Lecture 04-02
Loading data from file
Slicing개념

코드 중 shape = [None,3]는 들어오는 값을 의미 행 자유, 열 3
코드 중 tf.random_normal([3,1])에서는 3은 들어간 값(x), 1은 나가는 값(y).
코드 중tf.random_normal([1])에서는 1은 나가는 값(y)
Lecture 04 실습
Queue Runners
1)
filename_queue = tf.train.string_input_producer(
['data-01-test-score.csv', 'data-02-test-score.csv', ... ],
shuffle=False, name='filename_queue')
2)
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
3)
record_defaults = [[0.], [0.], [0.], [0.]]
xy = tf.decode_csv(value, record_defaults=record_defaults)

Lecture 05 강의
Lecture 05
알파는 learning rate, 그 뒤의 항이 gradiant
binary classification
예로 들의면 spam email detection spam or ham -> 0,1 encoding
기준이 되는 값을 지정 그리고 그 값을 기준으로 pass 와 fail 결정 가능.

0과 1사이로 압축을 시켜주면
곡선의 형태로..(시그모이드 형태로) 띄게 되고 식 또한 그렇게 된다.

Lecture 05-2
0과 1사이 값으로 출력을 내게 되는데 각각의 가설이되는 식이 다르다.
시그모이드는 shape도 그렇고 식을 봐도 그렇듯 linear하지는 않다.
local minimum이 아닌 global minimum을 찾아야 한다
logistic regression에는 또 그 에 맞는 cost function을 적용해야한다.

Lecture 05-3
logistic regression 실습
xdata는 입력
y_data는 출력
Lecture 05 실습
#train the model and print out the variables
for step in range(10001):
cost_val,
= sess.run([cost, train], feed_dict={X: x_data, Y: y_data})
if step % 200 == 0:
print(step, cost_val)
Lecture 06 강의
Lecture 06-1
Logistic regression
입력된 x값들을 Weight를 곱한 결과를 sigmoid를 통과 시킨후 prediction값 즉, yhat값을 출력한다. 그리고 그 결과를 통해 logistic regression한다.
Multinomial classification
예를 들어 A,B,C가 여러개씩 있는상황에서 A or not,B or not,C or not과 같이 기준에 따라 다르게 나눌 수 있다.
Matrix multiplication
dot produc를 통한 계산이 쓰인다.

lecture 06-2
Sigmoid
sigmoid를 통과하는 값은 0과 1사이의 것들이다. softmax는 우리가 원하는 결과의 특징 1. 0~1사이의 range를 갖는다. 2. 전체 합이 1인 probabilities의 형태를 띈다와 같은 내용을 만족시키기 위한것으로 sigmoid를 통과시키면 다음 내용을 만족시킨다.
softmax
one-hot encoding 을 통해 최댓값을 고르는 과정을 거치는 것으로 가장 큰값에 argmax를 취해 1로 만든다.
cross-entropy cost function
prediction값인 yhat값과 실제값인 y값사이의 element-wise연산을 통해 계산되는 것으로 틀린값일 때는 무한대의 값을 도출한다.
Logistic cost VS cross entropy
앞서서 봤던 logistic cost function과 cross entropy function은 서로 매우 닮아있는 것을 알 수 있다.
Gradient descent
alpha는 learning rate값인 것을 알 수 있고, 그 뒤에 붙는 미분 값은 경계면에서의 미분값인 것을 알 수 있다.
Lecture 06 실습
hypothesis = tf.nn.softmax(tf.matmul(X,W)+b)
all = sess.run(hypothesis, feed_dict={X: [[1, 11, 7, 9],
[1, 3, 4, 3],
[1, 1, 0, 1]]})
print(all, sess.run(tf.arg_max(all, 1)))
그에 대한 결과 값은 다음과 같이 나온다.
[[ 1.38904958e-03 9.98601854e-01 9.06129117e-06]
[ 9.31192040e-01 6.29020557e-02 5.90589503e-03]
[ 1.27327668e-08 3.34112905e-04 9.99665856e-01]][1 0 2]
#Cross entropy cost/loss
cost = tf.reduce_mean(-tf.reduce_sum(Y * tf.log(hypothesis), axis=1))
#Cross entropy cost/loss
cost_i = tf.nn.softmax_cross_entropy_with_logits(logits=logits,
labels=Y_one_hot)
cost = tf.reduce_mean(cost_i)

#reshape에 대한 내용
Y = tf.placeholder(tf.int32, [None, 1]) # 0 ~ 6, shape=(?, 1)
Y_one_hot = tf.one_hot(Y, nb_classes) # one hot shape=(?, 1, 7)
Y_one_hot = tf.reshape(Y_one_hot, [-1, nb_classes]) # shape=(?, 7)
#[-1, nb_classes]은 7을 의미.
Lecture 07 강의
Learning rate
learning rate이 너무 크면 over shooting, 너무 작으면 너무 느리다는 단점과 local minimum에 빠질 수 있다는 단점이 있음.
따라서 costfunction을 보면서 그 값을 조정해야한다.
data preprocessing
normalized data로 진행해야 한다. 중심점이 0이고 중심점으로 부터 흩어진 정도가 정규화되어있어야 좋다.
overfitting
너무 잘맞는 데이터로 학습시킬경우 실제 적용시 오히려 오류가 날 수 있다.
이에 대한 해결 방법으로는 더 많은 training data를 사용, feature수 줄이기, 정규화등이 있다.
Traing dataset, test dataset
쉽게 설명하면 training dataset은 교과서,validation dataset은 모의시험, test dataset은 시험으로 생각할 수 있다.

Lecture 07 실습
#데이터가 크거나 데이터 크기가 들쭉날쭉 할 때 normalized하는데 쓰인다.
xy = MinMaxScaler(xy)
#batch 100개로 잘라서 가져옴.
batch_xs, batch_ys = mnist.train.next_batch(100)
Lecture 08 강의
Backpropagation이 너무 깊은 네트워크망을 처리할 수 없자 그에대한 돌파구로 SVM과 Randomforest와 같은 방법이 생겨나기 시작했다.
Lecture 08 실습
keyword만 정리
Simple 1D array and slicing
2D Array(rank와 shape개념)
Shape, Rank, Axis
Matmul VS multiply
Broadcasting (주의해서 써야한다.)
Reduce Mean
Reduce Sum
Argmax
Reshape
Reshape(squeeze,expand)
Onehot
Casting
Stack
Ones and Zeros like
Zip

profile
cs/ce 전공 재학생입니다.

0개의 댓글