모두를 위한 딥러닝 강의 시즌1을 듣고 복습한 내용입니다.
cost가 최소화되는 W를 찾는 것!
Gradient descent algorithm (경사하강법)
- Minimize cost function
- minimization 문제에 자주 사용되었음
- w1, w2, w3... 여러 개 값이 있을 때도 사용 가능
- 경사도를 따라서 1 step 이동 -> 미분을 사용해서 경사를 구할 수 있음
Convex function
- 어느 점에 시작해도 항상 최솟값을 찾을 수 있음
텐서플로우 코드 (버전 2.0 이상)
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
x_train = [1, 2, 3, 4]
y_train = [0, -1, -2, -3]
tf.model = tf.keras.Sequential()
tf.model.add(tf.keras.layers.Dense(units=1, input_dim=1))
sgd = tf.keras.optimizers.SGD(lr=0.1)
tf.model.compile(loss='mse', optimizer=sgd) # 평균 제곱 오차
tf.model.summary()
# fit() trains the model and returns history of train
history = tf.model.fit(x_train, y_train, epochs=100)
y_predict = tf.model.predict(np.array([5, 4]))
print(y_predict)
# Plot training & validation loss values
plt.plot(history.history['loss'])
plt.title('Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Train', 'Test'], loc='upper left')
plt.show()
'딥러닝, 머신러닝 > 모두를 위한 딥러닝 강의 복습' 카테고리의 다른 글
Logistic Classification, Logistic Regression의 cost 함수 (0) | 2022.01.05 |
---|---|
TensorFlow로 파일에서 데이터 읽어오기 (0) | 2022.01.04 |
Multi-variable linear regression (0) | 2022.01.04 |
Linear Regression (0) | 2022.01.04 |
기본적인 Machine Learning 의 용어와 개념 설명 (0) | 2022.01.04 |