Skip to Main Content
Hands-On Unsupervised Learning with Python
book

Hands-On Unsupervised Learning with Python

by Giuseppe Bonaccorso
February 2019
Intermediate to advanced content levelIntermediate to advanced
386 pages
9h 54m
English
Packt Publishing
Content preview from Hands-On Unsupervised Learning with Python

Example of a Kohonen map

In this example, we want to train a square 8 × 8 Kohonen map to become receptive to the Olivetti faces dataset. As each sample is a 64 × 64 grayscale image, we need to allocate a weight matrix with a shape equal to (8, 8, 4,096). The training process can be very long; therefore, we will limit the map to 100 random samples (of course, the reader is free to remove this limit and train the model with the whole dataset).

As usual, let's start by loading and normalizing the dataset, as follows:

import numpy as npfrom sklearn.datasets import fetch_olivetti_facesfaces = fetch_olivetti_faces(shuffle=True)Xcomplete = faces['data'].astype(np.float64) / np.max(faces['data'])np.random.shuffle(Xcomplete)X = Xcomplete[0:100]
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

Hands-On Unsupervised Learning Using Python

Hands-On Unsupervised Learning Using Python

Ankur A. Patel
Introduction to Machine Learning with Python

Introduction to Machine Learning with Python

Andreas C. Müller, Sarah Guido

Publisher Resources

ISBN: 9781789348279Supplemental Content