SHARE
TWEET

Untitled

a guest Feb 17th, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def minmax(data):
  2.     data = StandardScaler().fit_transform(data)
  3.     centers = data[0:1]
  4.     centers_ids = set([0])
  5.     offset = 0
  6.     while True:
  7.         distances = np.zeros((data.shape[0], centers.shape[0]))
  8.         for i in range(centers.shape[0]):
  9.             for j in range(data.shape[0]):
  10.                 if j not in centers_ids:
  11.                     distances[j, i] = dist(data[j], centers[i])
  12.                 else:
  13.                     distances[j, i] = 0
  14.         min_distances = np.min(distances, axis = 1)
  15.         L = np.argmax(min_distances)
  16.         if min_distances[L] > (offset / centers.shape[0]):
  17.             centers = np.append(centers, data[L:L+1], axis = 0)
  18.             offset += min_distances[L]
  19.             centers_ids.add(L)
  20.         else:
  21.             min_distances = np.argmin(distances, axis = 1)
  22.             return (centers, min_distances)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top