无法估算python高斯拟合的协方差

时间:2018-07-08 14:45:39

标签: python python-3.x scipy data-fitting

我有一些我想拟合的数据,类似于您可以对Origin进行的处理,制作直方图,并使用高斯从计数中拟合出数据。我知道我可以适应正在测试的东西,但是我不断得到:

  

警告(来自警告模块):     文件“ C:... \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ scipy \ optimize \ minpack.py”,第794行       category = OptimizeWarning)   OptimizeWarning:无法估计参数的协方差

要使它正常工作,我缺少什么?与绘制图形相比,我更想从拟合中获取常数,即y0,xc,w,A,sigma,Height和标准误差。 我将此用作参考https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html。我将代码减少一些,因此仅包含相关部分。

import matplotlib.pyplot as plt
from matplotlib import style
#style.use('fivethirtyeight')
import numpy as np
from scipy.optimize import curve_fit


BinWidth = 10**-4
FileName = "902.txt"
DATA = []
def func(x, a, x0, sigma):
    return a*np.exp(-(x-x0)**2/(2*sigma**2))

n, bins, patches = plt.hist(DATA, bins=np.arange(min(DATA) - BinWidth*20 , max(DATA) + BinWidth*20, BinWidth),alpha=.5)

if (len(n) << len(bins)):
    n=np.append(n,0)
if (len(n) >> len(bins)):
    np.delete(n, len(n)-1)

popt, pcov = curve_fit(func, bins, n)

数据是:

  

90.248512268,90.2483596801,90.2489013671,90.2481231689,90.2484817504,90.248840332,90.2487792968,90.2489013671,90.2500305175,90.2486343383,90.2486572265,90.2482452392,90.2480010986,90.2482757568,90.2484207153,90.2481536865,90.2479476928,90.2483062744,90.2484817504,90.2481842041,90.2487182617,90.2480621337,90.2481536865,90.2482757568 ,90.2480621337,90.2483596801,90.2483062744,90.2482757568,90.2483291625,90.2483596801,90.2481842041,90.2481536865,90.2482147216,90.2481842041,90.2483062744,90.2480010986,90.2484207153,90.2483291625,90.2480926513,90.2480926513,90.2483291625,90.2480621337,90.248512268,90.2479476928,90.2479476928,90.2482757568,90.2478561401,90.2480316162,90.2485733032 ,90.2477340698、90.2478256225、90.2479476928、90.2482452392、90.2477340698、90.2480010986、90.2481536865、90.2478256225、90.2477035522、90.2480316162、90.2477645874、90.2477340698、90.2484512329、90.2480926513、90.2478256225、90.2484596 577,90.2480010986,90.2481536865,90.2483596801,90.2480316162,90.2485427856,90.248512268,90.2477340698,90.2484207153,90.2482452392,90.2478561401,90.2479476928,90.2478866577,90.2479476928,90.2483596801,90.2478256225,90.2480926513,90.2480621337,90.2483062744,90.2478561401,90.2480621337,90.2478866577,90.2481231689,90.2480621337,90.2482147216, 90.247680664,90.2478866577,90.2476501464,90.2479476928,90.2477951049,90.2480010986,90.2480010986,90.2480926513,90.2479782104,90.2480621337,90.2479171752,90.2481536865,90.2481536865,90.2479476928,90.2483291625,90.247680664,90.2479171752,90.2483062744,90.2482147216,90.2478866577,90.2477645874,90.2476501464,90.2476501464,90.2477035522,90.2481231689, 90.2480621337、90.2484207153、90.2481536865、90.2482757568、90.2480010986、90.2483062744、90.2480010986、90.2479476928、90.2478561401、90.2480010986、90.2480010986、90.2480621337、90.2476501464、90.2480621337、90.2479476476.9, 7216、90.2478866577、90.2481536865、90.2476196289、90.2475891113、90.2474975585、90.2477951049、90.2479171752、90.2473526、90.2479171752、90.2477340698、90.2478256225、90.2473220825、90.2479476928、90.2482452392、90.2478225、90.2472476786.7674 90.247680664,90.2474060058,90.2475891113,90.247680664,90.2480010986,90.2472610473,90.2475280761,90.2479476928,90.2477035522,90.2472305297,90.2477035522,90.2476196289,90.2476196289,90.2474975585,90.2477035522,90.2477951049,90.2478256225,90.2474975585,90.2473526,90.2472915649,90.2473526,90.2478256225,90.2472000122,90.2476196289,90.2476501464, 90.247138977、90.2470779418、90.2476501464、90.2477951049、90.2473526、90.2472610473、90.2479476928、90.2477340698、90.2474365234、90.2471084594、90.2478561401、90.2477340698、90.2473526、90.2472305297、90.2479782204.90 1、90.2478256225、90.2469024658、90.2474975585、90.2474365234、90.2480316162、90.247467041、90.247680664、90.2475891113、90.247680664、90.2475891113、90.2471694946、90.2475585937、90.2478866577、90.2475280761、90.24759.2472、94760.20.24764792476476289 90.2478866577,90.247680664,90.2479782104,90.2478561401,90.2480926513,90.2477645874,90.2476196289,90.2477951049,90.2478561401,90.2477035522,90.2479171752,90.2474060058,90.2472915649,90.2480926513,90.2480010986,90.2473754882,90.2482147216,90.2473754882,90.247467041,90.2477951049,90.2474975585,90.2477035522,90.2477035522,90.247680664,90.247680664, 90.2474060058、90.2481842041、90.2479782104、90.2479171752、90.2480010986、90.2478561401、90.2477645874、90.2477951049、90.2480621337、90.2480926513、90.2477951049、90.2478256225、90.2474365234、90.2475891113、90.24770355104、9。 90.2477645874,90.2474365234,90.2477951049,90.2478256225,90.2475891113,90.2477035522,90.2478256225,90.247467041,90.2477645874,90.2482147216,90.2479171752,90.2477645874,90.2477645874,90.2474365234,90.2478561401,90.2480621337,90.2477951049,90.2477035522,90.2479782104,90.2478256225,90.2476501464,90.2480621337,90.2479476928,90.2472000122,90.2480926513, 90.2477340698,90.2477645874,90.2476196289,90.2475585937,90.2475280761,90.2477951049,90.2474060058,90.2472915649,90.2476501464,90.2473754882,90.247138977,90.2472305297,90.2476501464,90.247680664,90.2474060058,90.2472915649,90.247680664,90.247467041,90.2477340698,90.2477035522,90.247680664,90.247680664,90.2479171752,90.2473754882,90.2475280761, 90.2479782104、90.2477035522、90.2475891113、90.2473220825、90.2479782104、90.247680664、90.2477340698、90.2477340698、90.2474365234、90.2476501464、90.2473220825、90.2473220825、90.2477951049、90.2473754882、90.2473526、90.24747022。 9476928,90.2475585937,90.247680664,90.2475280761,90.2474365234,90.2476501464,90.2474365234,90.2476501464,90.2478256225,90.2474975585,90.247467041,90.2475891113,90.2478866577,90.2477645874,90.247138977,90.2476196289,90.247467041,90.2477340698,90.2472915649,90.2474060058,90.2479476928,90.2474975585,90.2480010986,90.2474060058,90.2477035522, 90.2474975585,90.2477340698,90.2475891113,90.247467041,90.2475280761,90.247680664,90.2475280761,90.2473754882,90.2472305297,90.2473526,90.2475280761,90.2474975585,90.2475891113,90.2474060058,90.2476196289,90.2475280761,90.2476501464,90.2472915649,90.2476196289,90.2477035522,90.2473220825,90.2475891113,90.2472305297,90.2479476928,90.2477645874, 90.2476501464、90.2475280761、90.2473754882、90.2475891113、90.2472915649、90.2471694946、90.2475280761、90.2475891113、90.2474975585、90.2475891113、90.2476196289、90.247680664、90.2475891113、90.247467041、90.2477035522

0 个答案:

没有答案