Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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

3. A Classification Problem Using DNNs

Activity 3.01: Building an ANN

Solution:

  1. Import the following libraries:
    import pandas as pd
    import numpy as np
    from sklearn.model_selection import train_test_split
    from sklearn.utils import shuffle
    from sklearn.metrics import accuracy_score
    import torch
    from torch import nn, optim
    import torch.nn.functional as F
    import matplotlib.pyplot as plt
    torch.manual_seed(0)
  2. Read the previously prepared dataset, which should have been named dccc_prepared.csv:
    data = pd.read_csv("dccc_prepared.csv")
    data.head()

    The output should be as follows:

    Figure 3.14: dccc_prepared.csv

  3. Separate the features from the target:
    X = data.iloc[:,:-1]
    y = data["default payment next month"]
  4. Using scikit-learn's train_test_split function, split the dataset into training, validation, and testing sets. Use a 60:20:20 split ratio. Set random_state to 0:
    X_new, X_test, \
    y_new, y_test = train_test_split(X, y, test_size=0.2, \
      ...
lock icon The rest of the chapter is locked
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 $19.99/month. Cancel anytime
Banner background image