Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Classifying Flowers | Neural Networks in PyTorch
PyTorch Essentials
course content

Зміст курсу

PyTorch Essentials

PyTorch Essentials

1. PyTorch Introduction
2. More Advanced Concepts
3. Neural Networks in PyTorch

book
Challenge: Classifying Flowers

Завдання

Swipe to start coding

Your goal is to train and evaluate a simple neural network using the Iris dataset, which consists of flower measurements and species classification.

  1. Split the dataset into training and testing sets allocating 20% for the test set and setting random state to 42.
  2. Convert X_train and X_test into PyTorch tensors of type float32.
  3. Convert y_train and y_test into PyTorch tensors of type long.
  4. Define a neural network model by creating the IrisModel class.
  5. Implement two fully connected layers and apply the ReLU activation function in the hidden layer.
  6. Initialize the model with the correct input size, hidden layer size equal to 16, and output size.
  7. Define the loss as cross-entropy loss and the optimizer as Adam with a learning rate of 0.01.
  8. Train the model for 100 epochs by performing forward propagation, computing loss, performing backpropagation, and updating the model's parameters.
  9. Set the model to evaluation mode after training.
  10. Disable gradient computation during testing to improve efficiency.
  11. Compute predictions on the test set using the trained model.
  12. Determine the predicted class labels based on raw predictions.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 4
toggle bottom row

book
Challenge: Classifying Flowers

Завдання

Swipe to start coding

Your goal is to train and evaluate a simple neural network using the Iris dataset, which consists of flower measurements and species classification.

  1. Split the dataset into training and testing sets allocating 20% for the test set and setting random state to 42.
  2. Convert X_train and X_test into PyTorch tensors of type float32.
  3. Convert y_train and y_test into PyTorch tensors of type long.
  4. Define a neural network model by creating the IrisModel class.
  5. Implement two fully connected layers and apply the ReLU activation function in the hidden layer.
  6. Initialize the model with the correct input size, hidden layer size equal to 16, and output size.
  7. Define the loss as cross-entropy loss and the optimizer as Adam with a learning rate of 0.01.
  8. Train the model for 100 epochs by performing forward propagation, computing loss, performing backpropagation, and updating the model's parameters.
  9. Set the model to evaluation mode after training.
  10. Disable gradient computation during testing to improve efficiency.
  11. Compute predictions on the test set using the trained model.
  12. Determine the predicted class labels based on raw predictions.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 4
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt