如果没有提供有关数据背后过程的信息,则无法重新创建生成给定数据表的函数。
话虽如此,我们可以做一些推测。
由于它是一个“百分位”函数,它可能代表某种概率分布的累积值。一个非常常见的概率分布是正态分布,其“累积”对应物(即它的积分)是所谓的“误差函数”(“erf”)。
事实上,您的表格数据看起来很像平均值为 473.09 的变量的误差函数:
你的数据集:橙色;拟合误差函数(erf):蓝色
但是,协议并不完美,这可能是由于三个原因:
- 我用来生成误差函数参数的拟合过程没有使用正确的约束(因为我不知道我在建模什么!)
- 您的数据集并不代表精确正态分布,而是代表其基础分布为正态分布的真实世界数据。您的样本数据中偏离模型的特征将被完全忽略。
- 基础分布根本不是正态分布,它的积分恰好看起来像误差函数。
我真的没法说!
如果你想使用这个函数,这是它的定义:
import numpy as np
from scipy.special import erf
def fitted_erf(x):
c = 473.09090474
w = 37.04826334
return 50+50*erf((x-c)/(w*np.sqrt(2)))
测试:
In [2]: fitted_erf(439) # 17 from the table
Out[2]: 17.874052406601457
In [3]: fitted_erf(457) # 34 from the table
Out[3]: 33.20270318344252
In [4]: fitted_erf(474) # 51 from the table
Out[4]: 50.97883169390196
In [5]: fitted_erf(502) # 79 from the table
Out[5]: 78.23955071273468
但是,我强烈建议您检查在不了解您的数据源的情况下创建的拟合函数是否适合您的任务。
附言
如果你有兴趣,这是用于获取参数的代码:
import numpy as np
from scipy.special import erf
from scipy.optimize import curve_fit
tab=np.genfromtxt('table.csv', delimiter=',', skip_header=1)
# using a 'table.csv' file generated by Google Spreadsheets
x = tab[:,0]
y = tab[:,1]
def parametric_erf(x, c, w):
return 50+50*erf((x-c)/(w*np.sqrt(2)))
pars, j = curve_fit(parametric_erf, x, y, p0=[475,10])
print(pars)
# outputs [ 473.09090474, 37.04826334]
并生成情节
import matplotlib.pyplot as plt
plt.plot(x,parametric_erf(x,*pars))
plt.plot(x,y)
plt.show()