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?

  • 1
    You lost me on the "average total cost". What is an average total cost? Can there actually be an average total cost?
    – Pieter B
    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

1 Answer 1


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:


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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.