0
this post을 기반으로 ARIMA 모델에서 그리드 해치를하기 위해 무차별 대입을 사용하려하지만이를 실행할 수 없습니다. 나는이 원리의 증거를 보여주고 있지만, 나는 그 논쟁에 대해 무엇을 잘못하고 있는가?scipy.optimize.brute 사용
y = pd.DataFrame([0,1,4,9,16]) + 3
def objfunc(coeffs, endog):
exp = coeffs[0]
const = coeffs[1]
print(exp, const, endog)
out = 0
for i in range(4):
out += i**exp + const
return out
from scipy.optimize import brute
grid = (slice(0, 2, 1), slice(3, 4, 1))
brute(objfunc, ranges=grid, args=y)
(0, 3, 0)
(0, 3, 0)
(1, 3, 0)
...
TypeError: objfunc() takes exactly 2 arguments (1 given)
나는이 내 목표는 각각 순서에와있는이 같은 튜플 (_, _, _)이 (_, _, _, 12) seasonal_order이 기능을 최적화하기 위해 실제로 해결되면.
def objfunc(coeffs, endog):
order = coeffs[0]
seasonal = coeffs[1]
fit = sm.tsa.statespace.SARIMAX(endog, trend='n', order=order, seasonal_order=seasonal).fit()
return fit.aic()
편집 :이 코드는 (@sasha 덕분에) 작동 변수 이름은 더 명확하고, (I 오류의 기능을 최소화) 더 의미가 있습니다.
import pandas as pd
y = np.array([0,1,4,9,16]) + 3 #polynomial x^2+3 with x=0:4
def objfunc(coeffs, *args):
arr = args[0] # access first element of tuple: y
exp = coeffs[0] # assuming y should become endog
const = coeffs[1]
pol = [i**exp + const for i in range(len(y))]
print coeffs
return abs(sum(pol) - sum(arr))
from scipy.optimize import brute
grid = (slice(1, 3, 1), slice(2, 5, 1))
resbrute = brute(objfunc, ranges=grid, args=(y,), full_output=True, finish=None)
print("Best coeffs: {}".format(resbrute[0]))
print("Score with best coeffs: {}".format(resbrute[1]))
print("Grid: {}".format(resbrute[2].tolist()))
print("Scores for grid: {}".format(resbrute[3].tolist()))
는 당신이 바로 변수 이름입니다. 내 질문을 편집하고 답변을 포함 시켰습니다. SARIMAX 작업에 대한 최적화 작업을 수행 할 수 있으며 아마도 게시 할 것입니다. 고맙습니다 – aless80