Using TensorDataset
Structuring your data into a dataset is one of the first steps in training a PyTorch neural network. TensorDataset simplifies this by converting NumPy arrays into a format PyTorch can use.
In this exercise, you'll create a TensorDataset using the preloaded animals dataset and inspect its structure.
Latihan ini adalah bagian dari kursus
Introduction to Deep Learning with PyTorch
Petunjuk latihan
- Convert
Xandyinto tensors and create aTensorDataset. - Access and print the first sample.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
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)