Appendix

1. Introduction to Deep Learning and PyTorch

Activity 1.01: Creating a Single-Layer Neural Network

Solution

  1. Import the required libraries, including pandas, for importing a CSV file:

    import pandas as pd

    import torch

    import torch.nn as nn

    import matplotlib.pyplot as plt

  2. Read the CSV file containing the dataset:

    data = pd.read_csv("SomervilleHappinessSurvey2015.csv")

  3. Separate the input features from the target. Note that the target is located in the first column of the CSV file. Convert the values into tensors, making sure the values are converted into floats:

    x = torch.tensor(data.iloc[:,1:].values).float()

    y = torch.tensor(data.iloc[:,:1].values).float()

  4. Define the architecture of the model and store it in a variable named model. Remember ...

Get The Deep Learning with PyTorch Workshop now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.