My solution for the Codeproject "pandas pandas pandas" in the Module "clustering wine" of the course Data science doesn't work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

My solution for the Codeproject "pandas pandas pandas" in the Module "clustering wine" of the course Data science doesn't work

https://code.sololearn.com/c314GrkDTev0/?ref=app

2nd Apr 2022, 1:35 PM
Daniel
2 Answers
+ 1
To be a little more specific: it works for all testcases but the Third :-(
2nd Apr 2022, 1:54 PM
Daniel
0
https://www.sololearn.com/compiler-playground/cvUcsMq6W81C import numpy as np n, k, datapoints = int(input()), 2, [] for i in range(n): datapoints.append([float(x) for x in input().split()]) datapoints = np.array(datapoints) centroids = np.array([[0, 0], [2, 2]]) def euclidean_distance(x, y): return np.sum(np.square(x - y)) ed = np.zeros((n, k)) for i, c in enumerate(centroids): for j, d in enumerate(datapoints): ed[j, i] = euclidean_distance(c, d) nearest_c = np.argmin(ed, axis=1) for c in range(k): dps = datapoints[np.asarray(c==nearest_c).nonzero()] if len(dps) == 0: print(None) continue new_centroid = dps.mean(axis=0).round(2) print(new_centroid)
22nd Feb 2023, 6:44 PM
kwesiquest