I have 3 variables; Market_Price, Hours, Age.
Using optimize I found the relationship between each of the variables and the Market_Price.
Data:
hours = [1000, 10000, 11000, 11000, 15000, 18000, 37000, 24000, 28000, 28000, 42000, 46000, 50000, 34000, 34000, 46000, 50000, 56000, 64000, 64000, 65000, 80000, 81000, 81000, 44000, 49000, 76000, 76000, 89000, 38000, 80000, 69000, 46000, 47000, 57000, 72000, 77000, 68000]
market_Price = [30945, 28974, 27989, 27989, 36008, 24780, 22980, 23997, 25957, 27847, 36000, 25588, 23980, 25990, 25990, 28995, 26770, 26488, 24988, 24988, 17574, 12995, 19788, 20488, 19980, 24978, 16000, 16400, 18988, 19980, 18488, 16988, 15000, 15000, 16998, 17499, 15780, 8400]
age = [2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 7, 8, 8, 8, 8, 8, 13,]
The relationship I derived was:
Hours to market_price = log(h)*h1+h2,
Age to market_price = log(a)*a1+a2
Where h1, h2, a1, a2 are found using Scipy's Optimize Curve Fit.
Now I would like to combine all 3 into one calculation, whereby having the age and hours I could determine the market_price.
The way I have been doing it so far is by finding the ratio between the two by determining which combination has the smallest standard deviation.
std_divs = []
for ratio in ratios:
n = 0
price_difference_final = []
while n < len(prices):
predicted_price = (log(h)*h1+h1)*ratio + (log(a)*a1+a1)*(1-ratio)
price_difference_final.append(prices[n] - predicted_price)
n += 1
data = np.array(price_difference_final)
std_divs.append(np.std(data))
std_div = min(std_divs)
optimum_ratio = ratios[std_divs.index(min(std_divs))]
As you can see, I accomplish this by brute force which is not an elegant solution.
Furthermore, now I find that the relationship between the 3 cannot be expressed using a single ratio, instead the ratio needs to be sliding. As year increases the hours/age ratio decreases, giving age an increasing weight in regards to the market price.
Unfortunately, I haven't been able to implement this using Scipy's Curve Fit as it only accepts one pair of arrays.
Any thought of how this could be best achieved?