TensorDataset 사용하기
데이터를 데이터셋 형태로 구성하는 것은 PyTorch 신경망을 학습할 때 가장 먼저 하는 단계 중 하나예요. TensorDataset은 NumPy 배열을 PyTorch에서 사용할 수 있는 형식으로 바꿔주어 이를 간단하게 만들어 줍니다.
이 연습 문제에서는 미리 로드된 animals 데이터셋을 사용해 TensorDataset을 만들고, 그 구조를 살펴보겠습니다.
이 연습은 강의의 일부입니다
PyTorch로 배우는 딥러닝 입문
연습 안내
X와y를 텐서로 변환한 뒤TensorDataset을 생성하세요.- 첫 번째 샘플에 접근해 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
import torch
from torch.utils.data import TensorDataset
X = animals.iloc[:, 1:-1].to_numpy()
y = animals.iloc[:, -1].to_numpy()
# Create a dataset
dataset = ____(____, ____)
# Print the first sample
input_sample, label_sample = ____
print('Input sample:', input_sample)
print('Label sample:', label_sample)