September 2019
Intermediate to advanced
420 pages
10h 29m
English
The expectation-maximization algorithm is simple enough for us to code it ourselves. To do so, we will define a function, find_clusters(X, n_clusters, rseed=5), that takes as input a data matrix (X), the number of clusters we want to discover (n_clusters), and a random seed (optional, rseed). As will become clear in a second, scikit-learn's pairwise_distances_argmin function will come in handy:
In [7]: from sklearn.metrics import pairwise_distances_argmin... def find_clusters(X, n_clusters, rseed=5):
We can implement expectation-maximization for k-means in five essential steps:
Read now
Unlock full access