Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def minmax(data):
- data = StandardScaler().fit_transform(data)
- centers = data[0:1]
- centers_ids = set([0])
- offset = 0
- while True:
- distances = np.zeros((data.shape[0], centers.shape[0]))
- for i in range(centers.shape[0]):
- for j in range(data.shape[0]):
- if j not in centers_ids:
- distances[j, i] = dist(data[j], centers[i])
- else:
- distances[j, i] = 0
- min_distances = np.min(distances, axis = 1)
- L = np.argmax(min_distances)
- if min_distances[L] > (offset / centers.shape[0]):
- centers = np.append(centers, data[L:L+1], axis = 0)
- offset += min_distances[L]
- centers_ids.add(L)
- else:
- min_distances = np.argmin(distances, axis = 1)
- return (centers, min_distances)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement