Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Deep Learning with PyTorch Workshop

You're reading from   The Deep Learning with PyTorch Workshop Build deep neural networks and artificial intelligence applications with PyTorch

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781838989217
Length 330 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Hyatt Saleh Hyatt Saleh
Author Profile Icon Hyatt Saleh
Hyatt Saleh
Arrow right icon
View More author details
Toc

6. Analyzing the Sequence of Data with RNNs

Activity 6.01: Using a Simple RNN for a Time Series Prediction

Solution

  1. Import the required libraries, as follows:
    import pandas as pd
    import matplotlib.pyplot as plt
    import torch
    from torch import nn, optim
  2. Load the dataset and then slice it so that it contains all the rows but only the columns from index 1 to 52:
    data = pd.read_csv("Sales_Transactions_Dataset_Weekly.csv")
    data = data.iloc[:,1:53]
    data.head()

    The output is as follows:

    Figure 6.26: Displaying dataset for columns from index 1 to 52

  3. Plot the weekly sales transactions of five randomly chosen products from the entire dataset. Use a random seed of 0 when performing random sampling in order to achieve the same results as in the current activity:
    plot_data = data.sample(5, random_state=0)
    x = range(1,53)
    plt.figure(figsize=(10,5))
    for i,row in plot_data.iterrows():
        plt.plot(x,row)
    plt.legend(plot_data.index)
    plt.xlabel("Weeks...
lock icon The rest of the chapter is locked
arrow left Previous Section
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime