第十二周

1.

x = np.linspace(0,2,50)
y = np.sin(x-2) * np.sin(x-2) * np.exp(-x**2)
plt.figure(1)
plt.xlabel("x")
plt.ylabel("y")
plt.ylim(-0.1, 1)
plt.title(r"$f(x) = sin^2(x-2)e^{-x^2}$")
plt.annotate('local max', xy=(0.22, 0.9), xytext=(0.13, 0.5),
            arrowprops=dict(facecolor='black', shrink=0.05))
plt.plot(x,y)
plt.show()

2.

X = np.random.normal(loc=5,scale=5,size=(20,10))
b = np.random.normal(loc=0,scale=5,size=10)
z = np.random.normal(size=20)
y = np.dot(X,b) + z

b_e = np.ones(10)

def error(p,xxx,yyy):
    return np.dot(xxx,p)-yyy

b_e,cost=leastsq(error,b_e,args=(X,y)) 

plt.figure(2)

plt.xlabel("index")
plt.ylabel("value")
plt.plot(b, 'rx', label="True coefficients")
plt.plot(b_e, 'b', label="Estimated coefficients")
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.axis([0,9,-10,10])
plt.hlines(0,0,9 ,colors = "c", linestyles = "dashed")
plt.show()

3.

data = np.random.normal(scale=100, size=10000)
kernel = stats.gaussian_kde(data)
full_data = np.linspace(-500,500,10000)
est_data = kernel.evaluate(full_data)
plt.figure(3)
plt.hist(data, 30, density=True)
plt.plot(full_data, est_data)
plt.show()


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值