2017-12-05 12 views
0

scipy.optimize.curve_fit 함수에 예상 추측 시작 값을 입력하려고합니다. 는 this link another linkscsi.optimize.curve_fit에서 leastsq() 인수 'x0'오류가 발생했습니다.

에 따르면 그러나 나는 내가 다른 방법으로 시도의 X0에서 그들을 defind해야하며, 나는 다음과 같은 오류가 발생합니다. (참고 : x0 인수가 없으면 정상적으로 작동 함)

TypeError : leastsq() 인수 'x0'에 대해 여러 값이 있습니다.

나는 재현 예를 들어 아래 제공 :

import numpy as np 
import pandas as pd 
from sklearn.datasets import load_iris 
import scipy.optimize 
iris = load_iris() 
data1 = pd.DataFrame(data= np.c_[ iris['target'], iris['data']], columns= ['target'] + iris['feature_names']) 

def formula_nls(data, pot, sp): 
    return pot * np.tanh(data1.iloc[:,2] * sp/2) 

scipy.optimize.curve_fit(f = formula_nls, xdata= data1.iloc[:,1:], 
               ydata= data1.iloc[:,0], method = 'lm', 
              sigma = 1/data1.iloc[:,1], absolute_sigma=False, 
               x0 = np.ndarray([ 1, 2])) 

어쩌면 내가 실종 오전 간단한 일입니다. least_squares, 예를 들어, 이것은 API와 다른

p0 : None, scalar, or N-length sequence, optional

Initial guess for the parameters. If None, then the initial values will all be 1 (if the number of parameters for the function can be determined using introspection, otherwise a ValueError is raised).

가의 최소화 : 감사

는 는
+0

그건'np.array'하지'np.ndarray' – percusse

답변

2

사용 인수 x0curve_fit의 문서가 말할 때 왜 후자 : curve_fit에서 내부적으로

x0 : array_like with shape (n,) or float

Initial guess on independent variables. If float, it will be treated as a 1-d array with one element.

그리고 네, 당신의 p0becomes을 부여 x0least_squares의 : x0

res = leastsq(func, p0, Dfun=jac, full_output=1, **kwargs) 

내가이 인수로 취급 될 것으로 예상 curve_fit의 인수가 아닌 사용 대상 :

kwargs

Keyword arguments passed to leastsq for method='lm' or least_squares otherwise.

t는 의 전화 번호 x0과 함께 leastsq으로 x0으로 전달됩니다. 이 같은

뭔가 :

def fun(x0, **kwargs): 
    return 1 

print(fun(1)) 
# 1 
print(fun(1, x0=3)) 
# TypeError: fun() got multiple values for argument 'x0' 
+1

감사에 대한 도움이됩니다. 나는 내가 빠진 것이 있다는 것을 알았다. –