시작하기무료로 시작하기

여러 관측값/데이터 행에 네트워크 적용하기

이제 predict_with_network()라는 함수를 정의해서 여러 데이터 관측값에 대한 예측을 생성해 보겠습니다. 관측값은 input_data로 미리 로드되어 있습니다. 이전과 마찬가지로 weights도 미리 로드되어 있어요. 또한 이전 연습 문제에서 정의한 relu() 함수도 미리 로드되어 있습니다.

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

Python으로 시작하는 Deep Learning

강의 보기

연습 안내

  • input_data_rowweights 두 인자를 받아 네트워크의 예측값을 반환하는 predict_with_network() 함수를 정의하세요.
  • 각 노드의 입력값과 출력값을 계산해서 다음과 같이 저장하세요: node_0_input, node_0_output, node_1_input, node_1_output.
    • 노드의 입력값은 관련된 배열들을 원소별로 곱한 뒤 합을 구해 계산합니다.
    • 노드의 출력값은 해당 노드의 입력값에 relu() 함수를 적용해 계산합니다.
  • 노드에서 했던 것과 같은 방식으로 input_to_final_layermodel_output을 계산해 모델 출력을 구하세요.
  • for 반복문을 사용해 input_data를 순회하세요:
    • predict_with_network()을 사용해 input_data의 각 행(input_data_row)에 대한 예측을 생성하고, 각 예측값을 results에 추가하세요.

실습형 인터랙티브 연습

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

# Define predict_with_network()
def predict_with_network(input_data_row, weights):

    # Calculate node 0 value
    node_0_input = ____
    node_0_output = ____

    # Calculate node 1 value
    node_1_input = ____
    node_1_output = ____

    # Put node values into array: hidden_layer_outputs
    hidden_layer_outputs = np.array([node_0_output, node_1_output])
    
    # Calculate model output
    input_to_final_layer = ____
    model_output = ____
    
    # Return model output
    return(model_output)

# Create empty list to store prediction results
results = []
for input_data_row in input_data:
    # Append prediction to results
    results.append(____)

# Print results
print(results)     
코드 편집 및 실행