I am looking for a statistical model to detect grouping patterns among a population X of n element with respect to their association with k elements of population Y. In modern marketing, an example of that would be "customers who bought X also bought Y", such as on Amazon etc.
X (person) Y (purchase) ------------------------ Jimmy Lure Joe Fishing Rod Jimmy Fishing Rod Sue Sewing Machine Sue Thread Patty Sewing Machine Jack Tennis Balls
Above is just a very simple example. But imagine that 80% of people who bought a
Fishing Rod also bought
Lure and similar for
Sewing Machine vs
Thread. While the pattern may be obvious to the naked eye, I am looking for a more deterministic algorithm to detect this seemingly simple pattern. Imagine that this is a simple two dimensional array. Could you produce a pseudo code (or Java, Python, C or whatever suits you) algorithm that I could use to determine the most closely related elements in X based on their association with elements from Y?