# Algorithms to Determine How Much A Factor Contributes to A Total Value

Lets say that I have hundreds/thousands of objects(entries) in a database and each object contains 10 attributes. I have a way to quantitatively measure each attribute where a higher number implies that the object is better in that area. I also have a final price associated with that object. Is there any way to programatically (through maybe an algorithm) determine an approximation of how much each attribute contributes to the total cost?

In essence, I want to be able to estimate the

average total cost = a*attribute1+b*attribute2+.....+j*attribute10

by solving for a,b,...,j

I realize that this might be more of a statistics question than a programming question, but I am more interested in the implementation of this through programming than a fully statistics explanation.

Is this something more suited for scipy? numpy? some statistics framework?

• You lost me on the "average total cost". What is an average total cost? Can there actually be an average total cost? Commented Dec 25, 2012 at 8:40
• Where does the Python tag come in? Are you saying that you've already decided to implement this in Python? Commented Dec 25, 2012 at 10:11

You did not tell us if you know for sure that the final price stands in a relation to the attribute values, or if that is just a wild guess of yours. However, I take a guess on my own: I guess what you are looking for is an algorithm to choose a_1, a_2, ..., a_10 so that

``````q_j := sum(a_i *attribute_i_j) (where i=1,...10, j = 1,..., number of objects)
``````

approximates the price p_j of object j. In this equation, `attribute_i_j` is the value of the i-th attribute of object j. To optimize the price difference simultanously, one would typically minimize the sum of squares of the differences:

``````sum((p_j - q_j)^2)
``````

This is known as "linear least squares approximation", and you find the solution here in Wikipedia:

http://en.wikipedia.org/wiki/Linear_least_squares_%28mathematics%29#The_general_problem

To solve this with Python, I would recommend trying scipy's `leastsq` function:

http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.leastsq.html#scipy.optimize.leastsq

Last but not least, it would be helpful if you clarify if I got your intentions right, or if you want to solve a different problem.