Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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
Machine Learning Fundamentals

You're reading from   Machine Learning Fundamentals Use Python and scikit-learn to get up and running with the hottest developments in machine learning

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher
ISBN-13 9781789803556
Length 240 pages
Edition 1st Edition
Languages
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

Chapter 3: Supervised Learning: Key Steps

Activity 8: Data Partition over a Handwritten Digit Dataset

  1. Import the digits toy dataset using scikit-learn's datasets package and create a Pandas DataFrame containing the features and target matrices. Use the following code:
    from sklearn.datasets import load_digits
    digits = load_digits()
    import pandas as pd
    X = pd.DataFrame(digits.data)
    Y = pd.DataFrame(digits.target)

    The shape of your features and target matrix should be as follows, respectively:

    (1797,64) (1797,1)
  2. Choose the appropriate approach for splitting the dataset and split it.

    Conventional split approach (60/20/20%)

    Using the train_test_split function, split the data into an initial train set and a test set:

    from sklearn.model_selection import train_test_split
    X_new, X_test, Y_new, Y_test = train_test_split(X, Y, test_size=0.2)

    The shape of the sets that you created should be as follows:

    (1437,64) (360,64) (1437,1) (360,1)

    Next, calculate the value of the test_size, which...

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