Time Series Practical
Time Series Practical
PRN:1132220472
Answer:
import numpy as np
import seaborn as sb
import statsmodels.api as sm
import pandas as pd
df = pd.read_csv(r"C:\Users\ADMIN\Downloads\5_6321061767917079875.csv", index_col =
"Month", parse_dates = True)
df.head()
df.dropna()
missing_values = df.isnull() #for missing value
missing_values
df_filled
plt.xlabel('Year')
plt.ylabel('Passenger Number')
plt.show()
diff_df = df.diff().dropna()['#Passengers'].values
print(diff_df)
#e) Plot the autocorrelation and partial autocorrelation plots of the differenced series
sm.graphics.tsa.plot_acf(diff_df, ax=ax[0])
sm.graphics.tsa.plot_pacf(diff_df, ax=ax[1])
plt.show()
#f) Fit an ARIMA (1,1,1) model to the data and print model summary
print(arima_model.summary())
#g) Generate forecasts for the next 36 months.
forecast = arima_model.forecast(steps=36)
forecast
#h) Plot the forecasted values
plt.plot(df, label='Observed')
plt.plot(forecast, label='Forecast')
plt.xlabel('Year')
plt.ylabel('Passenger Numbers')
plt.legend()
plt.show()