13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

318

changes. Clearly this motivates many more avenues of research!

22.2 Bibliographic Note

K-Means Clustering is a well-known technique discussed in many machine learning textbooks. A

relatively straightforward introduction, without recourse to hard mathematics, is given in James

et al (2013)[59]. The basics of the algorithm are outlined as well as its pitfalls.

The graduate level books by Hastie et al (2009)[51] and Murphy (2012)[71] delve more deeply

into the "wider picture" of clustering algorithms, putting them into the probabalistic modelling

framework. They also place K-Means in context with other clustering algorithms such as Vector

Quantisation and Gaussian Mixture Models. Other books that discuss K-Means clustering

include Bishop (2007)[22] and Barber (2012)[20].

22.3 Full Code

# simulated_data.py

import itertools

import numpy as np

import matplotlib.pyplot as plt

from sklearn.cluster import KMeans

if __name__ == "__main__":

np.random.seed(1)

# Set the number of samples, the means and

# variances of each of the three simulated clusters

samples = 100

mu = [(7, 5), (8, 12), (1, 10)]

cov = [

[[0.5, 0], [0, 1.0]],

[[2.0, 0], [0, 3.5]],

[[3, 0], [0, 5]],

]

# Generate a list of the 2D cluster points

norm_dists = [

np.random.multivariate_normal(m, c, samples)

for m, c in zip(mu, cov)

]

X = np.array(list(itertools.chain(*norm_dists)))

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!