Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Introduction to Deep Learning with PyTorch

Cursus bekijken

Oefeninstructies

  • Convert X and y into tensors and create a TensorDataset.
  • Access and print the first sample.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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)
Code bewerken en uitvoeren