<jupyter_start><jupyter_text>Here P-value is 0.36 which is greater than 0.05, which means data is accepting the null hypothesis, which means data is non-stationary.Let’s try to see the first difference and seasonal difference:<jupyter_code>data_s['GDP growth rate First Difference'] = data_s['GDP growth (annual %)'] - data_s['GDP growth (annual %)'].shift(1)
data_s['GDP growth rate Seasonal First Difference']=data_s['GDP growth (annual %)'] - data_s['GDP growth (annual %)'].shift(5)
data_s.head(20)
adf_test(data_s['GDP growth rate Seasonal First Difference'].dropna())
data_s['GDP growth rate Seasonal First Difference'].plot()
from pandas.plotting import autocorrelation_plot
autocorrelation_plot(data_s['GDP growth (annual %)'])
plt.show()
fig = plt.figure(figsize=(12,8))
ax1 = fig.add_subplot(211) #top left
fig = sm.graphics.tsa.plot_acf(data_s['GDP growth rate Seasonal First Difference'].dropna(),lags=11,ax=ax1)
ax2 = fig.add_subplot(212) ##top right
fig = sm.graphics.tsa.plot_pacf(data_s['GDP growth rate Seasonal First Difference'].dropna(),lags=11,ax=ax2)<jupyter_output><empty_output><jupyter_text>Order For ARIMA model<jupyter_code>from pmdarima import auto_arima
data_fit = auto_arima(data_s['GDP growth (annual %)'], trace = True, suppress_warnings = True)
data_fit.summary()<jupyter_output>Performing stepwise search to minimize aic
 ARIMA(2,1,2)(0,0,0)[0] intercept   : AIC=inf, Time=1.17 sec
 ARIMA(0,1,0)(0,0,0)[0] intercept   : AIC=371.792, Time=0.01 sec
 ARIMA(1,1,0)(0,0,0)[0] intercept   : AIC=358.185, Time=0.09 sec
 ARIMA(0,1,1)(0,0,0)[0] intercept   : AIC=inf, Time=0.12 sec
 ARIMA(0,1,0)(0,0,0)[0]             : AIC=369.803, Time=0.04 sec
 ARIMA(2,1,0)(0,0,0)[0] intercept   : AIC=350.347, Time=0.07 sec
 ARIMA(3,1,0)(0,0,0)[0] intercept   : AIC=346.948, Time=0.06 sec
 ARIMA(4,1,0)(0,0,0)[0] intercept   : AIC=344.615, Time=0.08 sec
 ARIMA(5,1,0)(0,0,0)[0] intercept   : AIC=344.673, Time=0.06 sec
 ARIMA(4,1,1)(0,0,0)[0] intercept   : AIC=inf, Time=0.27 sec
 ARIMA(3,1,1)(0,0,0)[0] intercept   : AIC=inf, Time=0.20 sec
 ARIMA(5,1,1)(0,0,0)[0] intercept   : AIC=inf, Time=0.41 sec
 ARIMA(4,1,0)(0,0,0)[0]             : AIC=342.707, Time=0.06 sec
 ARIMA(3,1,0)(0,0,0)[0]             : AIC=345.013, Time=0.04 sec
 ARIMA(5,1,0)(0,0,0)[0]             : AIC=342.814, Time=0.06 sec
 A[...]<jupyter_text>Apply ARIMA model<jupyter_code>from statsmodels.tsa.arima_model import ARIMA
print(data_s.shape)
train_data = data_s.iloc[:-20]
test_data = data_s.iloc[-20:]
print(train_data.shape, test_data.shape)
model=ARIMA(train_data['GDP growth (annual %)'],order=(0,1,1))
model_fit=model.fit()
model_fit.summary()
start = len(train_data)
end = len(train_data) + len(test_data) - 1
data_s['forecast']=model_fit.predict(start=start,end=end,dynamic=True)
data_s[['GDP growth (annual %)','forecast']].plot()
model=sm.tsa.statespace.SARIMAX(data_s['GDP growth (annual %)'],order=(0, 1, 1),seasonal_order=(0,1,1,6))
results=model.fit()
data_s['forecast']=results.predict(start=start,end=end,dynamic=True)
data_s[['GDP growth (annual %)','forecast']].plot()
new_bd = data_s[['GDP growth (annual %)','forecast']]
data_for_rmse = new_bd[-20:]
data_for_rmse
from sklearn.metrics import mean_squared_error
import math
mse = mean_squared_error(data_for_rmse['GDP growth (annual %)'], data_for_rmse['forecast'])
rmse = math.sqrt(mse)
rmse
from sklearn.metrics import mean_absolute_error
mae = mean_absolute_error(data_for_rmse['GDP growth (annual %)'], data_for_rmse['forecast'])
print('MAE: %f' % mae)
data_for_r_squre = data_for_rmse[['GDP growth (annual %)','forecast']]
data_for_r_squre
from sklearn.metrics import r2_score
R_square = r2_score(data_for_r_squre['GDP growth (annual %)'], data_for_r_squre['forecast']) 
print(R_square) 
data_for_r_squre[['GDP growth (annual %)','forecast']].plot()
step = int(input('Enter how many year(Maximum 30 year) you need to know: '))
from pandas.tseries.offsets import DateOffset
future_dates=[data_for_rmse.index[-1]+ DateOffset(years=x)for x in range(0,step)]
future_datest_df=pd.DataFrame(index=future_dates[1:],columns=data_for_rmse.columns)
future_df=pd.concat([data_for_rmse,future_datest_df])
future_df['forecast'] = results.predict(start = 61, end = 92, dynamic= True)
future_df[['GDP growth (annual %)', 'forecast']].plot()
future_df[['forecast']].tail(step-1)
errors = abs(data_for_rmse['GDP growth (annual %)'] - data_for_rmse['forecast'])
mape = 100 * (errors / data_for_rmse['GDP growth (annual %)'])
accuracy = 100 - np.mean(mape)
print('Accuracy:', round(accuracy, 2), '%.')<jupyter_output>Accuracy: 81.01 %.
{'fraction_non_alphanumeric': 0.1746448087431694, 'fraction_numerical': 0.0605464480874317, 'mean_word_length': 6.782312925170068, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '574174', 'license': 'Apache-2.0', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1874, 'n_words': 339, 'path': 'Machine Learning Model & DataSet/GDP project.ipynb', 'repo_name': 'kowshir-bitto/Bangladesh-GDP-Growth-Rate-Development', 'size': '4575'}