시작하기무료로 시작하기

데이터를 상수로 정의하기

이 강의 전반에서 우리는 tensorflow 2.6.0을 사용하며, 각 연습 문제를 푸는 데 필요한 하위 모듈만 선택해서 임포트할 거예요. 보통은 미리 준비되어 있지만, 이번 연습에서는 tensorflow에서 constant를 직접 임포트해 보겠습니다.

constant를 임포트한 뒤에는 numpy 배열 credit_numpytensorflow 상수인 credit_constant로 변환할 거예요. 이 배열에는 신용카드 보유자 데이터셋의 특성 열이 들어 있으며, 아래 이미지에서 미리 볼 수 있어요. 이 데이터셋은 뒤의 장에서도 다시 사용할 예정입니다.

참고로 tensorflow 2에서는 데이터를 numpy 배열로도, tensorflowconstant 객체로도 사용할 수 있어요. constant를 사용하면 해당 객체로 수행되는 연산이 모두 tensorflow에서 처리되도록 보장합니다.

This image shows four feature columns from a dataset on credit card default: education, marriage, age, and bill amount.

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

Python으로 시작하는 TensorFlow

강의 보기

연습 안내

  • tensorflow 모듈에서 constant 하위 모듈을 임포트하세요.
  • credit_numpy 배열을 tensorflowconstant 객체로 변환하세요. 데이터 타입은 설정하지 마세요.

실습형 인터랙티브 연습

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

# Import constant from TensorFlow
from tensorflow import ____

# Convert the credit_numpy array into a tensorflow constant
credit_constant = constant(____)

# Print constant datatype
print('\n The datatype is:', credit_constant.dtype)

# Print constant shape
print('\n The shape is:', credit_constant.shape)
코드 편집 및 실행