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 ...

Get The Unsupervised Learning Workshop now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.