Python으로 시작하는 TensorFlow
Isaiah Hull
Visiting Associate Professor of Finance, BI Norwegian Business School
tensorflow 연산TensorFlow는 대표 손실 함수를 제공합니다
손실 함수는 tf.keras.losses()에서 사용
tf.keras.losses.mse()tf.keras.losses.mae()tf.keras.losses.Huber()
# 표준 별칭으로 TensorFlow 임포트
import tensorflow as tf
# MSE 손실 계산
loss = tf.keras.losses.mse(targets, predictions)
# 선형 회귀 모델 정의
def linear_regression(intercept, slope = slope, features = features):
return intercept + features*slope
# MSE를 계산하는 손실 함수 정의
def loss_function(intercept, slope, targets = targets, features = features):
# 선형 모델 예측값 계산
predictions = linear_regression(intercept, slope)
# 손실 반환
return tf.keras.losses.mse(targets, predictions)
# 테스트 데이터 입력에 대한 손실 계산
loss_function(intercept, slope, test_targets, test_features)
10.77
# 기본 데이터 입력에 대한 손실 계산
loss_function(intercept, slope)
5.43
Python으로 시작하는 TensorFlow