I am using rational regression to fit my data, how do I know what polynomials to divide?(What function to use?)

别等时光非礼了梦想. 提交于 2021-02-08 10:17:35

问题


I have a set of data:

10.28;3.615758755
60.12;3.409846973
87.24;2.360958276
92.37;2.288513587
130.87;1.940551693
164.01;1.770745686
215.87;1.60957984
245.42;1.548268275
251.26;1.53780944
252.14;1.536289363
261.74;1.520210896
384.91;1.385778494
458.68;1.339844772
492.59;1.323331777
600.94;1.281642094
6480.17;1.116976869
849.37;1.229511285
941.5;1.216845459
1280.98;1.185881122
1395.94;1.178804247
1470.04;1.180831814
1500.85;1.179158477
1861.04;1.15910996
2882.22;1.138164332
2997.18;1.136701833
6729.04;1.116347949
8959.82;1.112277925
14790.88;1.10743715
17567.38;1.106261719
18558.54;1.105927514
19637.11;1.105601588
33464.45;1.10328722
41473.89;1.104898287
83343.62;1.102639677
136991.14;1.102804824
325767.02;1.102357998

The left column is a price for manufacturing an object and the right is that same object's percent markup(In decimal form) when sold. The trend for this data is clearly rational. This is the code I am using for regression:

def func(xdata, a, b, c, d):
    return 1 / (a * ((b * xdata) ** d)) * c + 1.1
popt, pcov = optimization.curve_fit(func, xdata, ydata)
plot(xdata, ydata, 'o')
plot(xdata, func(xdata, *popt), "r-")
for x in xdata:
    x_position = xposition.index(x)
    guess = func(x, *popt)
    percent_of_error = ((abs(guess - ydata[x_position])) / 
    ydata[x_position]) * 100
    print(percent_of_error)
show()

I have tried variations of the function to try to get the best fit but for my purposes the fit has to be within 5% to the actual markup, meaning with the equation I need to be able to predict using the original price the markup within no more than 5% error. I am certain that the markups were determined by a rational equation as otherwise the owners of the objects would have had to input thousands of markups manually. The question I have is what two polynomials do I need to divide(So what function do I need?), or how do I find this out, in order to be able to get the most accurate line of best fit? Thanks in advance. My current function: 1 / (a * ((b * xdata) ** d)) * c + 1.1

来源:https://stackoverflow.com/questions/63064045/i-am-using-rational-regression-to-fit-my-data-how-do-i-know-what-polynomials-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!