Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Classifying Penguins | Neural Networks
PyTorch Essentials
course content

Course Content

PyTorch Essentials

PyTorch Essentials

1. PyTorch Basics
2. Preparing for Neural Networks
3. Neural Networks

book
Challenge: Classifying Penguins

Task
test

Swipe to begin your solution

Your goal is to train and evaluate a simple neural network using the palmer penguins dataset, which contains information about penguin species and various physical measurements.

  1. Load the Dataset:

    • Read the penguins.csv file into a Pandas DataFrame.
    • Handle missing values by dropping rows with any NaN values.
    • Encode the species column as integers (target variable).
  2. Prepare Features and Target:

    • Select bill_length_mm, bill_depth_mm, flipper_length_mm, and body_mass_g as features.
    • Encode the species column as the target.
  3. Split the Data:

    • Use an 80-20 split for train-test data.
  4. Create PyTorch Tensors:

    • Convert the features into FloatTensor and the target into LongTensor.
  5. Define a Neural Network:

    • Create a model class with one hidden layer using PyTorch’s nn.Module.
  6. Train the Model:

    • Use the CrossEntropyLoss function and the Adam optimizer.
    • Train for 100 epochs and print the loss every 10 epochs.
  7. Evaluate the Model:

    • Calculate test accuracy.
    • Display the confusion matrix to analyze the predictions.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 4
toggle bottom row

book
Challenge: Classifying Penguins

Task
test

Swipe to begin your solution

Your goal is to train and evaluate a simple neural network using the palmer penguins dataset, which contains information about penguin species and various physical measurements.

  1. Load the Dataset:

    • Read the penguins.csv file into a Pandas DataFrame.
    • Handle missing values by dropping rows with any NaN values.
    • Encode the species column as integers (target variable).
  2. Prepare Features and Target:

    • Select bill_length_mm, bill_depth_mm, flipper_length_mm, and body_mass_g as features.
    • Encode the species column as the target.
  3. Split the Data:

    • Use an 80-20 split for train-test data.
  4. Create PyTorch Tensors:

    • Convert the features into FloatTensor and the target into LongTensor.
  5. Define a Neural Network:

    • Create a model class with one hidden layer using PyTorch’s nn.Module.
  6. Train the Model:

    • Use the CrossEntropyLoss function and the Adam optimizer.
    • Train for 100 epochs and print the loss every 10 epochs.
  7. Evaluate the Model:

    • Calculate test accuracy.
    • Display the confusion matrix to analyze the predictions.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 4
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt