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 Unsupervised Learning Workshop

You're reading from   The Unsupervised Learning Workshop Get started with unsupervised learning algorithms and simplify your unorganized data to help make future predictions

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781800200708
Length 550 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Benjamin Johnston Benjamin Johnston
Author Profile Icon Benjamin Johnston
Benjamin Johnston
Christopher Kruger Christopher Kruger
Author Profile Icon Christopher Kruger
Christopher Kruger
Aaron Jones Aaron Jones
Author Profile Icon Aaron Jones
Aaron Jones
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface
1. Introduction to Clustering 2. Hierarchical Clustering FREE CHAPTER 3. Neighborhood Approaches and DBSCAN 4. Dimensionality Reduction Techniques and PCA 5. Autoencoders 6. t-Distributed Stochastic Neighbor Embedding 7. Topic Modeling 8. Market Basket Analysis 9. Hotspot Analysis Appendix

6. t-Distributed Stochastic Neighbor Embedding

Activity 6.01: Wine t-SNE

Solution:

  1. Import pandas, numpy, and matplotlib, as well as the t-SNE and PCA models from scikit-learn:
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    from sklearn.decomposition import PCA
    from sklearn.manifold import TSNE
  2. Load the Wine dataset using the wine.data file included in the accompanying source code and display the first five rows of data:
    df = pd.read_csv('wine.data', header=None)
    df.head()

    The output is as follows:

    Figure 6.25: The first five rows of the Wine dataset

  3. The first column contains the labels; extract this column and remove it from the dataset:
    labels = df[0]
    del df[0]
  4. Execute PCA to reduce the dataset to the first six components:
    model_pca = PCA(n_components=6)
    wine_pca = model_pca.fit_transform(df)
  5. Determine the amount of variance within the data described by these six components:
    np.sum(model_pca.explained_variance_ratio_)

    The output...

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