How to predict stock analysis - automatic ARIMA

In the previous , we find the same knn and linear regression, performance is not particularly good, take a look at the performance time series

Time series forecasting method is a kind of regression prediction method, which belongs to quantitatively predict, the basic principle is; on the one hand recognize the continuity of the development of things, the use of time-series data of past statistical analysis, suggesting that the development trend of things; on the other hand fully take into account factors arising from accidental random, in order to eliminate the effect of random fluctuations, using historical data for statistical analysis, and data for proper disposal, for trend forecasting.

Auto ARIMA

ARIMA is a very popular time series forecasting statistical methods. ARIMA models to predict future values ​​using past values. ARIMA There are three important parameters:

  • p (a value used to predict the past value)

  • q (a value of the past to predict the future prediction error)

  • D (differential sequence)

ARIMA parameter optimization requires a lot of time. Therefore, we will use an automatic ARIMA, automatically selects the minimum error (p, q, d) the best combination.

 

Plug one way, if you do not use automatic selection error, you can calculate the differential data, mapping and then manually choose the size pdq, if you are interested in this direction, I can be a small window or underneath the message, not much here do the introduction.

 

# Import library

from pyramid.arima import auto_arima

Sort by index # 

data = df.sort_index(ascending=True, axis=0)

 # Divide training set, testing set

train = data[:987]

valid = data[987:]

 # Remove the two sets of data close this column, the second line is not very clear feeling useless to know the big brother message area Ariadne

training = train['Close']

validation = valid['Close']

 # Model (automatic selection parameter)

model = auto_arima(training, start_p=1, start_q=1,max_p=3, max_q=3, m=12,start_P=0, seasonal=True,d=1, D=1, trace=True,error_action='ignore',suppress_warnings=True)

model.fit(training)

 #prediction

forecast = model.predict(n_periods=248)

forecast = pd.DataFrame(forecast,index = valid.index,columns=['Prediction'])

result

# Calculate rms

rms=np.sqrt(np.mean(np.power((np.array(valid['Close'])-np.array(forecast['Prediction'])),2)))

# The following two behavioral outcomes, may not be performed

rms

44.954584993246954

#plot drawing training of close, close and test the predictive value

plt.plot(train['Close'])

plt.plot(valid['Close'])

plt.plot(forecast['Prediction'])

inference

As we saw earlier, the automatic ARIMA model uses past data to understand the time series model. Using these values, the model to capture the growth trend in the series.

While forecasting using this technique is much better than the previous forecast of machine learning models to achieve, but these forecasts are still a far cry from the actual value.

As is apparent from the figure, the sequence of the model to capture a trend, but it ignores the effect of the season.

 

Reference: https://www.jiqizhixin.com/articles/2019-01-04-16

Guess you like

Origin www.cnblogs.com/xingnie/p/12232184.html