RuntimeError:找不到最佳参数:函数调用的数量已达到maxfev = 1000

时间:2018-08-21 16:25:28

标签: python pandas scipy

我有以下代码引发错误:

  

RuntimeError:找不到最佳参数:调用次数   功能已达到maxfev = 1000

我认为这是由于循环中的def功能造成的。 怎么解决?

我正在使用scipy中的curve_fit,我想为许多独立组找到更好的值。

我正在完美地工作。

谢谢!

RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 1000.


 df_fit = pd.DataFrame()

for (group, df_gp) in df.groupby(['label']):

df_gp.sort_values(['animal']).reset_index(drop=True)

if len(df_gp) > 0:
    if len(df_gp) % 2 == 0:
        df_gp = pd.concat([df_gp, df_gp.tail(1)], axis=0); 

    x = np.arange(1,len(df_gp)+1)
    y = df_gp['price']

    xx = np.linspace(x.min(),x.max(), len(df_gp))

    # interpolate + smooth
    itp = interp1d(x,y, kind='linear') #kind = 'linear', 'nearest' (dobre vysledky), slinear (taky ok), cubic (nebrat), quadratic - nebrat
    # window size must be odd
    window_size, poly_order = len(df_gp), 2
    yy_sg = savgol_filter(itp(xx), window_size, poly_order)

    def func(x, A, B, x0, sigma):
        return A+B*np.tanh((x-x0)/sigma)

    fit, _ = curve_fit(func, x, y)
    yy_fit = func(xx, *fit)

    #fit1 = np.poly1d(np.polyfit(x, y, 3))
    #df_gp = df_gp.drop_duplicates(subset= 'sku',keep = 'first', inplace =True)

    # pridani promennych do dataframe
    df_gp['yy_fit'] = yy_fit
    df_gp['yy_sg'] = yy_sg
    df_fit = pd.concat([df_fit,df_gp], axis = 0)    

df_fit = df_fit.sort_values(['sku']).reset_index(drop=True)

0 个答案:

没有答案