Skip to content

Instantly share code, notes, and snippets.

@grohith327
Created June 9, 2018 15:11
Show Gist options
  • Save grohith327/c1436b1f916c615bbd9a40ba8a8795c1 to your computer and use it in GitHub Desktop.
Save grohith327/c1436b1f916c615bbd9a40ba8a8795c1 to your computer and use it in GitHub Desktop.
pred = []
for point in test_data:
## Find distance between test data point and centroids
dis_point_c1 = ((c1[0]-point[0])**2 + (c1[1]-point[1])**2 +
(c1[2]-point[2])**2 + (c1[3]-point[3])**2)**0.5
dis_point_c2 = ((c2[0]-point[0])**2 + (c2[1]-point[1])**2 +
(c2[2]-point[2])**2 + (c2[3]-point[3])**2)**0.5
dis_point_c3 = ((c3[0]-point[0])**2 + (c3[1]-point[1])**2 +
(c3[2]-point[2])**2 + (c3[3]-point[3])**2)**0.5
## Find the cluster to which the point is closest to and append
## it to pred
distances = [dis_point_c1,dis_point_c2,dis_point_c3]
pos = distances.index(min(distances))
pred.append(pos)
## Print the predictions
print(pred)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment