경사하강법
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
데이터 소개
x_train = [1,2,3,4]
y_train=[0,-1,-2,-3]
tf.model=tf.keras.Sequential()
모델링
- units==output shape
- input_dim == input shape
tf.model.add(tf.keras.layers.Dense(units=1,input_dim=1))
- SGD == standard gradient descendent, lr==learning rate(=step size)
sgd=tf.keras.optimizers.SGD(lr=0.1)
- MSE == mean_sqaure_error, 1/m * sig(y'-y)^2
tf.model.complie(loss='mse', optimizer=sgd)
print summary of the model to the terminal
tf.model.summary()
fit() executes training
tf.model.fit(x_train, y_train, epochs=200)
predict() returns predicted value
y_predict=tf.model.predict(np.array([5,4]))
print(y_predict)
출력 결과
[[-3.9975324]
[-2.9987302]]