Example of Sanger's network

For this Python example, we consider a bidimensional zero-centered dataset X with 500 samples (we are using the function defined in the first chapter). After the initialization of X, we also compute the eigendecomposition, to be able to double-check the result:

import numpy as npfrom sklearn.datasets import make_blobsX, _ = make_blobs(n_samples=500, centers=2, cluster_std=5.0, random_state=1000)Xs = zero_center(X)Q = np.cov(Xs.T)eigu, eigv = np.linalg.eig(Q)print(eigu)[ 24.5106037   48.99234467]print(eigv)[[-0.75750566 -0.6528286 ]
 [ 0.6528286  -0.75750566]]n_components = 2W_sanger = np.random.normal(scale=0.5, size=(n_components, Xs.shape[1]))W_sanger /= np.linalg.norm(W_sanger, axis=1).reshape((n_components, 1)) ...

Get Mastering Machine Learning Algorithms now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.