【问题标题】:What are the weight values to use in numpy polyfit and what is the error of the fit在 numpy polyfit 中使用的权重值是多少,拟合的误差是多少
【发布时间】:2013-11-09 04:16:21
【问题描述】:

我正在尝试对 numpy 中的一些数据进行线性拟合。

Ex(其中 w 是我对该值的样本数,即对于点 (x=0, y=0) 我只有 1 个测量值,该测量值是 2.2,但对于点 (1,1) 我有2 个测量值,值为 3.5

x = np.array([0, 1, 2, 3])
y = np.array([2.2, 3.5, 4.6, 5.2])
w = np.array([1, 2, 2, 1])

z = np.polyfit(x, y, 1, w = w)

所以,现在的问题是: 对于这些情况,在 polyfit 中使用 w=w 是否正确,或者我应该使用 w = sqrt(w) 我应该使用什么?

另外,如何从 polyfit 中获取拟合误差?

【问题讨论】:

    标签: python numpy statistics curve-fitting


    【解决方案1】:

    如果您有正态分布的测量值,那么每个值的不确定性将与1/sqrt(n) 成正比,其中n 是测量次数。你想通过不确定性的倒数来衡量你的适合度,所以你的第二个猜测是最好的:w=np.sqrt(n)

    要获得参数的协方差,请同时提供cov=True

    x = np.array([0, 1, 2, 3])
    y = np.array([2.2, 3.5, 4.6, 5.2])
    n = np.array([1, 2, 2, 1])
    
    p, c = np.polyfit(x, y, 1, w=np.sqrt(n), cov=True)
    

    cov 矩阵的对角线是每个参数的个体方差,当然非对角线是协方差。所以最有可能你想要的“拟合误差”是这些对角线的平方根:

    e = np.sqrt(np.diag(c))
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-16
    • 2015-02-26
    • 2020-07-27
    • 2020-11-14
    • 2015-09-17
    • 2020-03-22
    • 1970-01-01
    • 2011-01-24
    相关资源
    最近更新 更多