시작하기무료로 시작하기

모델 가중치 개선하기

잘하셨어요! 이제 필요한 기울기(slope)를 계산하셨네요. 이제 그 기울기를 사용해 모델을 개선해 볼 차례입니다. 가중치에 기울기를 더하면 올바른 방향으로 이동합니다. 하지만 너무 멀리 이동할 수도 있어요. 따라서 먼저 더 작은 학습률을 사용해 그 방향으로 한 걸음만 움직여 보고, 모델이 실제로 개선되는지 확인하는 것이 좋습니다.

가중치는 weights, 타깃의 실제 값은 target, 입력 데이터는 input_data로 미리 로드되어 있습니다. 초기 가중치에서의 예측값은 preds에 저장되어 있어요.

이 연습은 강의의 일부입니다

Python으로 시작하는 Deep Learning

강의 보기

연습 안내

  • 학습률을 0.01로 설정하고 원래 예측의 오차를 계산하세요. 이 부분은 이미 완료되어 있습니다.
  • weights에서 learning_rateslope의 곱을 빼서 업데이트된 가중치를 계산하세요.
  • weights_updatedinput_data를 곱해 합을 구해 업데이트된 예측값을 계산하세요.
  • 새 예측값의 오차를 계산하고 error_updated에 저장하세요.
  • 'Submit Answer'를 눌러 업데이트된 오차를 원래 오차와 비교해 보세요!

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Set the learning rate: learning_rate
learning_rate = 0.01

# Calculate the predictions: preds
preds = (weights * input_data).sum()

# Calculate the error: error
error = preds - target

# Calculate the slope: slope
slope = 2 * input_data * error

# Update the weights: weights_updated
weights_updated = ____

# Get updated predictions: preds_updated
preds_updated = ____

# Calculate updated error: error_updated
error_updated = ____

# Print the original error
print(error)

# Print the updated error
print(error_updated)
코드 편집 및 실행