Last active
August 2, 2017 08:58
-
-
Save rohan-varma/d8b4f3fd4fa93a45c4b4048f0c5df6d6 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
def classify(cell_feature_vector, sickle_cluster, red_cluster, white_cluster): | |
#first, get the minimum of the distances to the known centroids. | |
sickle_dist = dist(cell_feature_vector, sickle_cluster.centroid) | |
red_dist = dist(cell_feature_vector, red_cluster.centroid) | |
white_dist = dist(cell_feature_vector, white_cluster.centroid) | |
min_dist = min(sickle_dist, red_dist, white_dist) | |
#check which centroid minimized the distance, and then check if this minimum distance is less than the furthest outlier | |
#that was still correctly classified. | |
if(min_dist == sickle_dist): | |
if(min_dist <= sickle_cluster.MAX_OUTLIER_DIST): | |
#if this vector was closer to the sickle cluster's centroid than the furthest outlier still classified as a sickle cell, | |
#then add it to the dataset, recompute the centroid, and return the label. | |
sickle_cluster.add(cell_feature_vector) | |
recompute_centroid(sickle_cluster) | |
return "sickle cell" | |
elif(min_dist == red_dist): | |
if(min_dist <= red_cluster.MAX_OUTLIER_DIST): | |
red_cluster.add(cell_feature_vector) | |
recompute_centroid(red_cluster) | |
return "red blood cell" | |
else: | |
if(min_dist <= white_cluster.MAX_OUTLIER_DIST): | |
white_cluster.add(cell_feature_vector) | |
recompute_centroid(white_cluster) | |
return "white blood cell" | |
return "Unable to classify cell" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment