+ 3

DS With Python last project

Hello, I need help with the last project of DS with python course(Pandas Pandas Pandas) My code doesn’t pass the last 3 test cases, but passing the first two. I can’t look at the last, help please. Here’s my try: n = int(input()) X = [] for i in range(n): X.append([float(x) for x in input().split()]) from sklearn.preprocessing import StandardScaler from sklearn.cluster import KMeans import numpy as np from sklearn.metrics.pairwise import euclidean_distances import math scale = StandardScaler() scale.fit(X) X_scaled = scale.transform(X) X=np.array(X) kmeans = KMeans(n_clusters=2, random_state=1) kmeans.fit(X) s=(kmeans.cluster_centers_) for a in s: print(np.around(a,2))

20th Dec 2020, 5:37 PM
BatOchir Artur
BatOchir Artur - avatar
2 Réponses
- 1
The Answer n = int(input()) import numpy as np x = np.zeros((n)) y = np.zeros((n)) p = np.array([0, 0]) c00 = np.array([0, 0]) c22 = np.array([2, 2]) count0 = 0 count1 = 0 x0 = 0 y0 = 0 x1 = 0 y1 = 0 for i in range (n) : x[i], y[i] = [float(z) for z in input().split()] for i in range (n) : p[0] = x[i] p[1] = y[i] d00 = np.sqrt(((c00-p)**2).sum()) d22 = np.sqrt(((c22-p)**2).sum()) if d22<d00 : x1 += x[i] y1 += y[i] count1 += 1 else : x0 += x[i] y0 += y[i] count0 += 1 if count0 != 0 : x0 = round(x0 / count0, 2) y0 = round(y0 / count0, 2) print(np.array([x0, y0])) else : print(None) if count1 != 0 : x1 = round(x1 / count1, 2) y1 = round(y1 / count1, 2) print(np.array([x1, y1])) else : print(None)
21st Jan 2021, 11:35 AM
Ali Mustafa Ali
Ali Mustafa Ali - avatar