In [1]:
d_small = np.loadtxt("data/small_2dclust.dat", delimiter=' ')

plt.figure(figsize=(10,8))

plt.scatter(x=d_small[:,1],
            y=d_small[:,2],
            color='blue',
            marker='o',
            s=200,
            alpha=0.4
           )
labels = ['{0}'.format(i) for i in range(d_small.shape[0])]
for label, x, y in zip(labels, d_small[:, 1], d_small[:, 2]):
    plt.annotate(
        label, 
        xy = (x, y), xytext = (-20, 20),
        textcoords = 'offset points', ha = 'right', va = 'bottom',
        bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5),
        arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
    
plt.title('A Toy Dataset', size=20)
plt.xlabel('$x_1$', size=25)
plt.ylabel('$x_2$', size=25)

plt.tick_params(axis='both', which='major', labelsize=18)

plt.show()

## Computing the densities
den_small = cal_density(d_small[:,1:3], 1.5)

# Computing the minimum distance to high density peaks
mdist2peaks_small = cal_minDist2Peaks(d_small, den_small)

import prettytable
pt = prettytable.PrettyTable


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-183838dc4ff6> in <module>()
----> 1 d_small = np.loadtxt("data/small_2dclust.dat", delimiter=' ')
      2 
      3 plt.figure(figsize=(10,8))
      4 
      5 plt.scatter(x=d_small[:,1],

NameError: name 'np' is not defined

In [2]:
import prettytable
pt = prettytable.PrettyTable(["Index", "Density", "Min. Dist."])
for i in range(d_small.shape[0]):
    pt.add_row([i, den_small[i], mdist2peaks_small[i]])
print(pt)
print(den_small)
print(mdist2peaks_small)
plot_decisionGraph(den_small, mdist2peaks_small, 1.7)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-92463d72cd98> in <module>()
      1 import prettytable
      2 pt = prettytable.PrettyTable(["Index", "Density", "Min. Dist."])
----> 3 for i in range(d_small.shape[0]):
      4     pt.add_row([i, den_small[i], mdist2peaks_small[i]])
      5 print(pt)

NameError: name 'd_small' is not defined

In [ ]:
def find_nearestNeigb(d, den_arr, centroids):
    ## finding the nearest neighbor of each point
    n = d.shape[0]
    nearestNeigb = np.repeat(-1, n)
    for i in range(n):
        if i in centroids:
            nearestNeigb[i] = i
        else:
            mindist = 999
            indxNeigb = -1
            for j in range(n):
                if i != j:
                    dist_ij = euclidean_dist(d[i,:], d[j,:])
                    if dist_ij <= mindist:
                        if den_arr[i] > den_arr[j]:
                            mindist = dist_ij
                            indxNeigb = j
                        elif den_arr[i] == den_arr[j]:
                            if j in centroids:
                                mindist = dist_ij
                                indxNeigb = j
                                
#find_nearestNeigb(d_small, den_small, np.array())