栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

拟合高斯函数

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

拟合高斯函数

看一下将任意曲线拟合到数据的答案。基本上,您可以使用它

scipy.optimize.curve_fit
来使您想要的任何功能适合您的数据。下面的代码显示了如何使高斯拟合某些随机数据(此SciPy-User邮件列表帖子的贷方)。

import numpyfrom scipy.optimize import curve_fitimport matplotlib.pyplot as plt# Define some test data which is close to Gaussiandata = numpy.random.normal(size=10000)hist, bin_edges = numpy.histogram(data, density=True)bin_centres = (bin_edges[:-1] + bin_edges[1:])/2# Define model function to be used to fit to the data above:def gauss(x, *p):    A, mu, sigma = p    return A*numpy.exp(-(x-mu)**2/(2.*sigma**2))# p0 is the initial guess for the fitting coefficients (A, mu and sigma above)p0 = [1., 0., 1.]coeff, var_matrix = curve_fit(gauss, bin_centres, hist, p0=p0)# Get the fitted curvehist_fit = gauss(bin_centres, *coeff)plt.plot(bin_centres, hist, label='Test data')plt.plot(bin_centres, hist_fit, label='Fitted data')# Finally, lets get the fitting parameters, i.e. the mean and standard deviation:print 'Fitted mean = ', coeff[1]print 'Fitted standard deviation = ', coeff[2]plt.show()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/638270.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号