Ways to calculate similarity

前端 未结 6 1514
执念已碎
执念已碎 2020-12-23 22:49

I am doing a community website that requires me to calculate the similarity between any two users. Each user is described with the following attributes:

age, skin ty

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 23:17

    Give each attribute an appropriate weight, and add the differences between values.

    enum SkinType
        Dry, Medium, Oily
    
    enum HairLength
        Bald, Short, Medium, Long
    
    UserDifference(user1, user2)
        total := 0
        total += abs(user1.Age - user2.Age) * 0.1
        total += abs((int)user1.Skin - (int)user2.Skin) * 0.5
        total += abs((int)user1.Hair - (int)user2.Hair) * 0.8
        # etc...
        return total
    

    If you really need similarity instead of difference, use 1 / UserDifference(a, b)

提交回复
热议问题