Python RuntimeError:未找到最佳参数:函数调用数已达到maxfev=1000

Python RuntimeError:未找到最佳参数:函数调用数已达到maxfev=1000,python,pandas,scipy,Python,Pandas,Scipy,我有以下代码,它会引发错误: RuntimeError:未找到最佳参数:调用的次数 函数已达到maxfev=1000 我认为这是由于循环中的def func。 怎么能修好呢 我正在使用scipy提供的曲线拟合,我希望为许多独立组找到更好的值 我的工作没有循环完美 谢谢 RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 1000. df_fit = pd.D

我有以下代码,它会引发错误:

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

我认为这是由于循环中的def func。 怎么能修好呢

我正在使用scipy提供的曲线拟合,我希望为许多独立组找到更好的值

我的工作没有循环完美

谢谢

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)

你试过增加maxfev吗?曲线拟合(func,x,y,maxfev=5000)是的,那么我有TypeError:“NoneType”对象不支持项赋值,但在哪里?我使用这种语法,曲线拟合没有问题。你使用的和我贴的完全一样吗?它说df_gp是none,但在df中,它只是一个与原始问题无关的组。你想修好maxfev,问题解决了。问另一个问题,但首先修复代码