In [9]:
%matplotlib inline
# pairwise distances looks at the distances between each
# record and finds closest members of the matrix.
In [10]:
from sklearn.metrics import pairwise
from sklearn.datasets import make_blobs
import numpy as np
In [11]:
points, labels = make_blobs()
In [12]:
distances = pairwise.pairwise_distances(points)
In [13]:
np.diag(distances)[:5]
Out[13]:
In [14]:
ranks = np.argsort(distances[0])
In [15]:
ranks[:5]
Out[15]:
In [26]:
print points.shape
points[ranks][:5]
Out[26]:
In [17]:
import matplotlib.pyplot as plt
In [25]:
f,ax = plt.subplots(figsize=(7,5))
ax.scatter(points[ranks][0], points[ranks][1])
ax.legend(loc='best')
In [ ]: