Skip to content

Instantly share code, notes, and snippets.

@laing20333
Last active August 29, 2015 14:10
Show Gist options
  • Save laing20333/399bb251715802779c40 to your computer and use it in GitHub Desktop.
Save laing20333/399bb251715802779c40 to your computer and use it in GitHub Desktop.
python example
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