Contenido del Curso
Neural Networks with PyTorch
Neural Networks with PyTorch
Challenge: Classifying Penguins
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.
-
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).
- Read the
-
Prepare Features and Target:
- Select
bill_length_mm
,bill_depth_mm
,flipper_length_mm
, andbody_mass_g
as features. - Encode the
species
column as the target.
- Select
-
Split the Data:
- Use an 80-20 split for train-test data.
-
Create PyTorch Tensors:
- Convert the features into
FloatTensor
and the target intoLongTensor
.
- Convert the features into
-
Define a Neural Network:
- Create a model class with one hidden layer using PyTorch’s
nn.Module
.
- Create a model class with one hidden layer using PyTorch’s
-
Train the Model:
- Use the CrossEntropyLoss function and the Adam optimizer.
- Train for 100 epochs and print the loss every 10 epochs.
-
Evaluate the Model:
- Calculate test accuracy.
- Display the confusion matrix to analyze the predictions.
Solución
¡Gracias por tus comentarios!
Challenge: Classifying Penguins
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.
-
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).
- Read the
-
Prepare Features and Target:
- Select
bill_length_mm
,bill_depth_mm
,flipper_length_mm
, andbody_mass_g
as features. - Encode the
species
column as the target.
- Select
-
Split the Data:
- Use an 80-20 split for train-test data.
-
Create PyTorch Tensors:
- Convert the features into
FloatTensor
and the target intoLongTensor
.
- Convert the features into
-
Define a Neural Network:
- Create a model class with one hidden layer using PyTorch’s
nn.Module
.
- Create a model class with one hidden layer using PyTorch’s
-
Train the Model:
- Use the CrossEntropyLoss function and the Adam optimizer.
- Train for 100 epochs and print the loss every 10 epochs.
-
Evaluate the Model:
- Calculate test accuracy.
- Display the confusion matrix to analyze the predictions.
Solución
¡Gracias por tus comentarios!