Created
June 9, 2018 15:11
-
-
Save grohith327/c1436b1f916c615bbd9a40ba8a8795c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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