python做有置信区间的拟合_在Python中为线性拟合(带两个参数)生成置信区间等高线图...

这需要一些蛮力,但是下面的步骤会在正确的间隔内生成一个椭圆。这不是一个令人满意的解决方案,但它产生了我所追求的情节。在import numpy as np

import matplotlib.pyplot as plt

from matplotlib.patches import Ellipse

import math

# set of x,y values (with y errors) to which a linear fit will be applied

x = np.array([1, 2, 3, 4, 5])

y = np.array([1.7, 2.1, 3.5, 3.2, 4.4])

erry = np.array([0.2, 0.2, 0.2, 0.3, 0.3])

ax = plt.subplot(111)

# apply fit to x,y array weighted by 1/erry^2

p2, V = np.polyfit(x, y, 1, w=1/erry, cov=True)

# define a chi square function into which parameter estimates are passed

def chisq(param1, param0):

csq = np.sum(((param1*x + param0 - y)/erry) ** 2)

return csq

# arrange labels for the coefficients so matches form y = theta1*x + theta0

theta1 = p2[0]

theta0 = p2[1]

# show

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值