List similarity?

Posted on 2010-08-12
Last Modified: 2012-05-10

I have an app where users can mark products. A user might generate a list of strings of products they marked like:


I want to find other users which have generated *similar* lists of marked product strings. I star "similar" because it's difficult for me to define.

This user would be the most similar:

    truck, wagon, bottle, dog

This user would be a little less similar:

    truck, wagon, bottle, dog, red

This user would also be a little less similar:

    truck, bottle, dog

This user has zero similarity:


This is probably some type of search, I just don't know the name. I want to find users that have similar tastes in the products they marked,

Question by:DJ_AM_Juicebox
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +3
LVL 13

Accepted Solution

themrrobert earned 100 total points
ID: 33425389
You will have to create your own algorithm, Especially if you plan to have a dynamic list now or in the future, it could change the order, thus impeding efforts even further.

The perfect function for this would be worth a great deal of cash.

Here is a good starting point:

$arrayUser1 = split("\n",$UserData1);
$arrayUser2 = split("\n",$UserData2);

this creates two arrays.

Loop through both, in a for x, for y, next y, next x format and add 1 point for each entry that matches.

For each user, divide the number of matches by the number of items of user1. (dividing by user2 gives you the converse 'similarity').

This should give you a good start, let me know if you have any questions
LVL 27

Expert Comment

ID: 33425419
" I star "similar" because it's difficult for me to define. "
If you find "similar" difficult to define, how do you expect the computed to do better?

Author Comment

ID: 33425420
>> The perfect function for this would be worth a great deal of cash.

Ha yeah I realize this has many useful applications.

I can't think of anything better than the solution you propose. Is there a common name for this problem though? I want to reference it a post I'm writing - like "the list similarity problem"? I doubt I'll find a solution for it, but if it's a known problem, I can site it as such and carry on!!

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

LVL 27

Expert Comment

ID: 33425448
"Is there a common name for this problem though?"
Try The Similarity Problem"

Do not let my previous comment discourage you too much.
One current related problem is face recognition software

Author Comment

ID: 33425461
Yeah bad wording on my part. I meant I don't know what term to label this problem as.

If a user has 4 items in their list, and I want to find the most similar users, those users would each have a similarity of "1", generated by dividing the number of matched items by max(total items in their own lists, total number of items in the original user's list):

    userA { red, green, blue }

    user1 { red, blue }  2 / 3 = 0.66

    user2 { green, blue, red }    3 / 3  = 1

    user3 { red, green, blue, yellow } 3 / 4 = 0.75


    similarity = matchedItems / max(setUserA.size(), setUserCurrent.size());  

LVL 27

Assisted Solution

aburr earned 100 total points
ID: 33425500
"  similarity = matchedItems / max(setUserA.size(), setUserCurrent.size());"
It looks like you are well on your way especially if the users construct their lists by selecting from a menu so that the items have a well defined form.
ie red will not be confused with redish

Author Comment

ID: 33425526
Yeah the solution by themrrobert gives the correct answer, the problem is hoping to do it at scale. For instance, if I have a database of 1 million users, there's no way I can cycle through all of them to do the computation. I would need to precompute some value each time they add a new item to their list and store it in their profile so I could at least get a rough set of users to iterate over in a single select statement.

Even better would be a single precomputed value to sort on which just orders the similarity for me in one select! The problem is that the criteria for similarity is variable and depends on the user the computation is being done for.

It's interesting and not easy to solve in 7 minutes!

LVL 84

Expert Comment

ID: 33425551
> if I have a database of 1 million users
About how many products would be in the database, and about how many would you expect each user to mark?

Author Comment

ID: 33425580
The number of products in the database is large, over 10 million.

The average number of items a user marks is 50.

LVL 84

Assisted Solution

ozo earned 100 total points
ID: 33425784
So this seems to be the model you are using
But for a dataset that large, speed could be a problem
LVL 12

Assisted Solution

PCableGuy earned 100 total points
ID: 33426098

Is there any advantage of making everyone the same string length along with 'fake' characters for an item that they didn't choose? Does this make it easier or harder to compute, or roughly the same?
Database of Choices, Ascending Order
bottle, dog, duck, red, truck, wagon

New User, hasn't chosen anything yet.
######, ###, ####, ###, #####, #####

User 1
bottle, dog, ####, ###, truck, wagon

User A
bottle, dog, ####, red, truck, wagon

User B
bottle, dog, ####, ###, truck, #####

User C
######, ###, duck, ###, #####, #####

Author Comment

ID: 33426161

Yeah was thinking of something like that, but the set of products is not fixed, new products are added every day. Also there are over 10 million products so the string would be huge (per user too). Also I would have to update every user's string when new products are added to keep it the 'missin' items sorted and up to date.

I can sort products as users mark a new product, I haven't thought of a way that that helps in a sql context though!

LVL 12

Expert Comment

ID: 33426358
LVL 27

Assisted Solution

tliotta earned 100 total points
ID: 33433359
Consider also that you might find value in tracking how many times each product is chosen for a listb. If 9M products have never been chosen, there's not much reason to pay attention to them in any algorithm.

Also, you might find value in weighting related to the number of times a product is chosen. If a customer lists four products that no one else has ever chosen, that list might have a total "weight" of zero, or something along those lines. Regardless, there will clearly be no other customers with a similar list -- it's not necessary even to check.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Guide to the PMT, FV, IPMT and PPMT Functions In MS Excel we have the PMT, FV, IPMT and PPMT functions, which do a fantastic job for interest rate calculations.  But what if you don't have Excel ? This article is for programmers looking to re…
Introduction On a scale of 1 to 10, how would you rate our Product? Many of us have answered that question time and time again. But only a few of us have had the pleasure of receiving a stack of the filled out surveys and being asked to do somethi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question