In [1]:
from sklearn.datasets import make_blobs
import numpy as np
import sys
if "../" not in sys.path:
sys.path.append("../")
from unsupervised.kmeans import KMeans
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['figure.figsize'] = (10.0, 8.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
import seaborn as sns
sns.set_context('notebook')
sns.set_style('white')
# for auto-reloading external modules
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
%autoreload 2
In [2]:
X, y = make_blobs(centers=4, n_samples=500, n_features=2,
shuffle=True, random_state=2046)
clusters = len(np.unique(y))
model = KMeans(K=clusters, max_iters=150)
model.fit(X)
In [3]:
model.plot()