Last active
August 29, 2015 14:10
-
-
Save laing20333/399bb251715802779c40 to your computer and use it in GitHub Desktop.
python example
This file contains hidden or 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 kp_distance(object_x, object_y, Wc): | |
''' Distance function for two objects | |
''' | |
res = 0.0 | |
for attr_idx in xrange(0, len(object_x)): | |
cur_type = type(object_x[attr_idx]) | |
if( (cur_type == str) or (cur_type == np.string_) ): | |
# categorical attribute | |
if (object_x[attr_idx] == object_y[attr_idx]): | |
res = res + Wc | |
else: | |
# numerical attribute | |
tmp = object_x[attr_idx] - object_y[attr_idx] | |
res = res + tmp * tmp | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment