In a dataset, we observe sets of points gathered together. With k-means, we will categorize all the points into groups, or clusters.
Using k-means to cluster data
Getting ready
First, let's walk through some simple clustering; then we'll talk about how k-means works:
import numpy as np
import pandas as pd
from sklearn.datasets import make_blobs
blobs, classes = make_blobs(500, centers=3)
Also, since we'll be doing some plotting, import matplotlib as shown:
import matplotlib.pyplot as plt
%matplotlib inline #Within an ipython notebook
How to do it…
We...