Skip to Main Content
The Unsupervised Learning Workshop
book

The Unsupervised Learning Workshop

by Aaron Jones, Christopher Kruger, Benjamin Johnston, Richard Brooker, John Wesley Doyle, Priyanjit Ghosh, Sani Kamal, Ashish Pratik Patil, Philip Solomon, Geetank Raipuria
July 2020
Intermediate to advanced content levelIntermediate to advanced
550 pages
9h 58m
English
Packt Publishing
Content preview from The Unsupervised Learning Workshop

Appendix

1. Introduction to Clustering

Activity 1.01: Implementing k-means Clustering

Solution:

  1. Import the required libraries:

    from sklearn.datasets import make_blobs

    from sklearn.cluster import KMeans

    from sklearn.metrics import accuracy_score, silhouette_score

    import matplotlib.pyplot as plt

    import pandas as pd

    import numpy as np

    from scipy.spatial.distance import cdist

    import math

    np.random.seed(0)

    %matplotlib inline

  2. Load the seeds data file using pandas:

    seeds = pd.read_csv('Seed_Data.csv')

  3. Return the first five rows of the dataset, as follows:

    seeds.head()

    The output is as follows:

    Figure 1.25: Displaying the first five rows of the dataset

    Figure 1.25: Displaying the first five rows of the dataset

  4. Separate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Supervised Learning Workshop

The Supervised Learning Workshop

Blaine Bateman, Ashish Ranjan Jha, Benjamin Johnston, Ishita Mathur
The Machine Learning Workshop - Second Edition

The Machine Learning Workshop - Second Edition

Hyatt Saleh, John Wesley Doyle, Akshat Gupta, Harshil Jain, Vikraman Karunanidhi, Subhojit Mukherjee, Madhav Pandya, Subhash Sundaravadivelu

Publisher Resources

ISBN: 9781800200708Supplemental Content