시작하기무료로 시작하기

여러 데이터 포인트로 확장하기

가중치가 다르면 단일 예측에서 정확도가 달라진다는 것을 확인했어요. 하지만 보통은 많은 데이터 포인트에서 모델 정확도를 측정해야 합니다. 이제 두 가지 서로 다른 가중치 세트(weights_0, weights_1)에 대해 모델 정확도를 비교하는 코드를 작성해 보겠습니다.

input_data는 배열의 리스트입니다. 이 리스트의 각 항목에는 단일 예측을 만들기 위한 데이터가 들어 있습니다. target_actuals는 숫자의 리스트입니다. 이 리스트의 각 항목은 우리가 예측하려는 실제 값입니다.

이번 연습에서는 sklearn.metricsmean_squared_error() 함수를 사용합니다. 이 함수는 실제 값과 예측 값을 인수로 받습니다.

또한 미리 로드된 predict_with_network() 함수를 사용합니다. 이 함수는 첫 번째 인수로 데이터 배열, 두 번째 인수로 가중치를 받습니다.

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

Python으로 시작하는 Deep Learning

강의 보기

연습 안내

  • sklearn.metrics에서 mean_squared_error를 임포트하세요.
  • for 루프로 input_data의 각 행을 순회하세요:
    • 각 행에 대해 predict_with_network() 함수를 사용해 weights_0으로 예측한 뒤 model_output_0에 추가하세요.
    • weights_1에 대해서도 동일하게 수행하여 예측 값을 model_output_1에 추가하세요.
  • mean_squared_error() 함수를 사용해 먼저 model_output_0, 그다음 model_output_1의 평균제곱오차를 계산하세요. 첫 번째 인수는 실제 값(target_actuals), 두 번째 인수는 예측 값(model_output_0 또는 model_output_1)이어야 합니다.

실습형 인터랙티브 연습

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

from sklearn.metrics import mean_squared_error

# Create model_output_0 
model_output_0 = []
# Create model_output_1
model_output_1 = []

# Loop over input_data
for row in input_data:
    # Append prediction to model_output_0
    model_output_0.append(____)
    
    # Append prediction to model_output_1
    model_output_1.append(____)

# Calculate the mean squared error for model_output_0: mse_0
mse_0 = ____

# Calculate the mean squared error for model_output_1: mse_1
mse_1 = ____

# Print mse_0 and mse_1
print("Mean squared error with weights_0: %f" %mse_0)
print("Mean squared error with weights_1: %f" %mse_1)
코드 편집 및 실행