# Is it possible to predict groups vs groups in machine learning?

I have a problem that I think machine learning can solve. I'm new to it however and don't know where to start so any pointers to appropriate solving methods/guides etc for the problem are appreciated. I've searched a bit and couldn't find any questions similar to this, but most likely because I dont know exactly what to search for:

Lets say we have a bunch of fruits: a,b,c,d,e,f which all have two factors associated with it, a price and a quality. Every day in a store the customers can choose between two bundles(g1,g2), each consisting of two fruits with varying price and quality(p,q). The 4 fruits every day must be unique, so g1 cannot have a fruit in g2. The customers then buy one bundle each. They value the price and quality, but are probably also influenced by outside factors such as what fruit it is and what it is combined with.

Is it possible to create a training set from this?
I came up with two ways to represent this:
The simplest way i could think of: let a fruit x be represented as x:{x_p,x_q}, a group as g1(a,b), and a training element would then be defined as day(g1,g2) which we will use to train our machine.
The second way was to let the fruits contain a present flag to mark if they are in a group or not, x:{x_p,x_q,present} and a group would then become g1(a,b,c,d,e,f) and a day still day(g1,g2)

Is it possible to do it the first way without data for several fruits, or is it just implementation specific?
How would one train for the mirroring case of day(g1(a,b),g2(c,d)) vs day(g1(c,d),g2(a,b)), by just creating the mirrored training element or is something that the machine could figure out on its own?
While this is a minimum example, what would be different if we were to cover more fruits(5/bundle) from a larger fruit pool(20)?
Can we use it to predict which bundle is more likely to be picked even if that group/fruit combo hasn't been evaluated in the set?

Another way I thought of was training on the groups, but I think that would result in a flat score for the groups and most likely miss relationships between the groups, such as g1 is preferred over g2 which is preferred over g3 which is preferred over g1? Is this true or would a machine be able to understand that too?

I was looking a bit at the javascript libraries brain and mind and thought that it might be possible with one of them, but I dont know what type of algorithm/solving method I'm looking for. Any suggestions for libraries to solve this in, preferrably python/php/java/javascript are appreciated!

Also if someone could add suitable tags to the question would be great!

EDIT: same as with the group mirroring, how do we distinguish the groups, do we need to sort the fruits alphabetically or can a machine handle it too? (apple, banana) should be identical to (banana,apple)

## 3 Answers

I think, you need to look carefully through popular ranking algorithms. I would suggest to start from Elo, at a glance, it could help you to solve the problem. I worked only with "classical" "1-vs.-1" version. But here are some thoughts on your case.

Consider every bundle as a team of two players; every customer's choice as a duel. The main issue here would be the "teams randomness", as you have no constant team compositions. But you can try to solve it, using average ratings of team members. With the large number of duels and "teams" you will get enough data to predict the outcome for brand new mixtures of fruits.

It's quite hard to understand what your actual goal is.

I understood you want to calculate optimal fruit bundles from a daily given set of fruits which may not have any fruit in common.

The easiest way to go about would be to just accumulate data how often each fruit is bought and take this as a measure of value for the customer. Then you could assume the bundling does not matter. From here you can just split up the fruit baskets by ranking the fruits according to their value and assign every odd element to basket one and every even element to basket two.

If you are really sure the composition of the basket matters because there are interactions between fruits you have to do a different strategy. If you can accumulate vast amounts of data, you could just sell every possible combination of baskets and again take the sales as a value measure.

• Yes, the composition is crucial,i was thinking if i.e. citrus fruits dont mix well with nuts, but nuts mix well with berries and berries and citrus makes an awesome composition. Otherwise just a regular weighted measure would work. Is it possible to analyze things like this with machine learning? – Fhurrur Mar 4 '16 at 15:55
• It is possible but from my feeling for your task it is infeasible. – Tobias Würfl Mar 8 '16 at 22:58

You could represent your input with numerical values for each fruit, negative if the fruit is in basket 1, positive if it's in basket 2 and 0 otherwise. This representation generalizes to larger baskets.

The representation will cause some algorithms, such as logistic regression, to take advantage of the symmetry of the training set. For other algorithms like k-nearest neighbor, you can mirror the training data - for each example, include another example with the identities of the groups reversed - which would let you use separate variables for each fruit-basketID pair.