# What type of technique can be used to solve this question?

Apology for the ambiguous title, I do not know the term.

I have data of some products which a few variables: origin, weight, brand. For example:

Product A = "China, 100g, Brand X"

Product B = "Japan, 50g, Brand Y"

Product C = "China, 30g, Brand Y"

... and so on. All products are homogeneous - you may assume they are all same type of bread, just with different attributes.

These products are not sold separately, but in bundle, e.g.

Bundle 1: 3 x Product A + 1 x Product B + 2 x Product C => $500 Bundle 2: 1 x Product E + 2 x Product F =>$700

(Usually each product exists only in 1 bundle)

I have the data of many bundles and prices. Is there a way to estimate the individual price of each product?

==Edited==

If we represent the bundles as linear equations directly it looks:

3*A + 1*B + 2*C = 500

1*E + 2*F = 700

Since all variables A,B,C etc. appear in only 1 equation, I do not know how to solve it. But we have the attributes of each product, and that the price of each product can be determined by these attributes.

• I don't know if I'm missing something, but it seems to me that you don't need the origin, weight and brand data at all, just to use the bundle configuration information as a system of linear equations and solve it e.g. with Cramer's rule.
– noe
Apr 18 at 10:50
• @noe I thought about this too, but the problem is none of the products exists in >1 bundle, thus I struggle to set it up as a linear system of equation. Please see my edit. Apr 19 at 2:23
• This is an example of "multiple-instance learning"; but, it doesn't satisfy the assumption behind the regression generalization listed on wikipedia and I'm not sure if there's any literature on this variant. Apr 26 at 12:55

The price of each product can be determined by these attributes.

I think we can try to make use of this information.

Suppose for a start, we assume that price of product $$i$$, $$X_i$$, is a linear combination of the attributes $$\sum_{j} a_{j}x_{ij}$$ where parameters $$a_j$$ is what we want to learn.

The bundle equation of bundle $$k$$ is of the form of

$$\sum_{i}b_{ki}X_i=p_k$$

Now replacing

$$\sum_{i}b_{ki}\left(\sum_{j} a_{j}x_{ij}\right)=p_k$$

and hence we can try to solve for the $$a_j$$ say using Gaussian elimination.

In general, $$X_i$$ can be a parametrized nonlinear function of $$x_{ij}$$ and we have to learn the corresponding parameters.

To handle the nonlinear case, one of the possibility is as follows

consider the price $$X_i$$ is a nonlinear function of feature $$x_{ij}$$ where $$j=1, \ldots, m$$.

$$X_i = f(x_{i1}, \ldots, x_{im} | \theta)$$

Our goal is to learn $$\theta$$ such that a loss function $$\sum_k\sum_i L (b_{ki} f(x_{i1}, \ldots, x_{im} | \theta) , p_k)$$ is minimized where $$b_{ki}$$ has been given to us.

For example, we can choose our loss function to be $$\frac1{K}\sum_k\sum_i (b_{ki} f(x_{i1}, \ldots, x_{im} | \theta) - p_k)^2$$ where $$K$$ is the number of bundle.

One possibility

• The input of the algorithm: Features of each product, i.e. for the input layer, one node for each feature of the product, $$x_{i1}, \ldots, x_{im}$$
• Hidden Layers: Be creative and explore, this is where the parameters $$\theta$$ come in. Use nonlinear activation functions to introduce nonlinearity.
• output layer: One node for each product, $$f(x_{i1}, \ldots, x_{im} | \theta)$$, this is at the product level where we estimate the price of each product.
• Loss function: $$\frac1{K}\sum_k\sum_i (b_{ki} f(x_{i1}, \ldots, x_{im} | \theta) - p_k)^2$$, this is at bundle level where the real price is being used to evaluate how good is our prediction.
• thanks, let me try. For the case where we assume nonlinear function, any pointer to what optimization techniques can be used? Apr 19 at 9:15
• maybe try to tune some neural network? Apr 19 at 14:24
• I think a neutral network could work, with batches being prespecified as the bags. Then the network is predicting item-level prices, but you only need the loss function defined at the bundle level. Apr 24 at 22:27
• Or perhaps in the architecture itself, a bundle is 2d, you do most operations only along rows, and at the end sum-pooling. Apr 24 at 22:34

Substitute in the attributes of each bundle, using 1-hot encoding for the categories of country and brand.

So given:

A = China, 100g, Brand X
B = Japan, 50g, Brand Y
C = China, 30g, Brand Y
D = Germany, 30g, Brand Y
E = Germany, 75g, Brand Z


 3*A + 1*B + 2*C = 500
1*E + 2*F = 700


we can make (I'm using c/j/g for countries, w for weight-in-grams, x/y/z for brands):

5*c + 1*j + 0*g + 410*w + 3*x + 3*y + 0*z = 500
0*c + 0*j + 3*g + 180*w + 0*x + 1*y + 2*z = 700


Obviously you are going to need more equations than you have attributes, to be able to solve it.

BTW, if you have an attribute with a lot of categories causing you trouble you can drop it, group it, or quantify it. For instance if you have 30 brands, you could make a judgement call for each and group them into high/low-value brands, so you only have two categories. Even better is to assign each brand a "brand quality" number from say 0 to 100. Now you've replaced 30 one-hot columns with a single number, and you will need much less data.

For your question about non-linear relations, once you have the data in the above format, you can run it through any machine learning algorithm, such as linear models, random forest, or neural net, giving it the training task of predicting the price.

EDIT based on OP's comment: As there is relatively little data (20-30 bundles), what I would do is first try and get the linear version to solve. Then check that it is giving sensible answers (giving more value to famous brands, and heavier products). Then I'd use random forest (or even a simple decision tree) to see what non-linear interactions it is discovering. I'd then manually add those as extra features to the data, and run the linear model again.

When data is limited like this I'd also do the old-fashioned idea of asking domain experts. They might tell you Japanese bread is in fashion, but only in small sizes, so then you can add "Japan and <50g" as a non-linear feature.

• Thanks for the reply. I am good with the linear case (as @Siong Thye Goh answered), but struggle on how to setup as an ML/optimization problem for non-linear case. I mean, I cannot assume A = c + 100w + x as A may not be linearly related with c, w and x. Apr 24 at 2:12
• What type of non-linear relationships do you imagine? If you had some semi-realistic sample data, enough to get a solution out of, we could show some sample code. (It might also be useful to say how much data you have in total, just as an order of magnitude, as dozens vs. hundreds vs. millions would change the approach.) Apr 24 at 7:30
• I don't know what kind of nonlinear relationship would be. If I know, I can just substitute it into the equation above and solve it like the linear case. That's the reason to resort to ML - I need the algorithm to figure this out. For a starter, just assume the dataset is modest, a few hundred products and couple tens of bundles. Apr 24 at 11:05
• @lpounng I expanded on my answer a bit. Hope it helps. Apr 25 at 21:49
• thanks. The part I find hard to visualize is how to format the input to feed into an ML algorithm. Usually we have (feature A,B,C) -> target, but here we have [product A's](feature A,B,C) + [product B's](feature A,B,C) + [product C's](feature A,B,C) -> target, and it is where I struggle on. Apr 26 at 10:33