July 2017
Intermediate to advanced
382 pages
9h 13m
English
Setting up k-means works exactly the same as in the previous examples. We tell the algorithm to perform at most 10 iterations and stop the process if our prediction of the cluster centers does not improve within a distance of 1.0:
In [2]: import cv2... criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER,... 10, 1.0)... flags = cv2.KMEANS_RANDOM_CENTERS
Then we apply k-means to the data as we did before. Since there are 10 different digits (0-9), we tell the algorithm to look for 10 distinct clusters:
In [3]: import numpy as np... digits.data = digits.data.astype(np.float32)... compactness, clusters, centers = cv2.kmeans(digits.data, 10, None,... criteria, 10, flags)
And done!
Similar to the N x 3 matrix that ...
Read now
Unlock full access