pandas - Python: Automatically choose parameters for ARMA model -


i trying fit arma model time series data. haven't find functions can automatically choose parameter. below code wrote beginner python hence believe code can optimised.

can give me ideas on how to:

  1. do vectorization on double loop
  2. quicker way parameter choosing

much appreciate.

    parameter_bound = 3      # creating 2-d array, storing residuals of 2 different parameters of arma model     residuals = [[0 x in range(parameter_bound)] x in range(parameter_bound)]      model = [[0 x in range(parameter_bound)] x in range(parameter_bound)]      # calculate residuals each parameter combinations     in range(parameter_bound):          j in range(parameter_bound):              model[i][j] = sm.tsa.arma(input_data, (i,j)).fit()              residuals[i][j] = sum(abs(model[i][j].resid))      # find parameters lowest residuals     parameters = np.argmin(residuals)      parameter1 = parameters/parameter_bound      parameter2 = parameters - parameters/parameter_bound*parameter_bound      # use model lowest residuals prediction data     prediction = model[parameter1][parameter2].resid + input_data 

i'm not sure you're expecting, replace lists numpy arrays (i don't think it'll improve specific code):

import numpy np residuals = np.zeros((parameter_bound, parameter_bound)) model = np.zeros((parameter_bound, parameter_bound), np.object) 

also, aware np.argmin axis=none returns index flattened array, if want return model parameters of model lowest residuals might try:

prediction = model.ravel()[np.argmin(residuals)].resid + input_data 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -