# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# ### Import Library

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pylab as plt
from matplotlib.pylab import rcParams
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
import sklearn
import math
from sklearn.metrics import mean_squared_error, mean_absolute_error   

# +
df = pd.read_csv("Los_Angeles_International.csv", parse_dates = [0], index_col =0, dayfirst= True, thousands = ",")


print(df)
# -

# ### Splitting the data

# +
train = df.iloc[:60]
test = df.iloc[49:]
for_comparing = df.iloc[60:]


for_comparing.head(10)
# -

plt.subplots(figsize=(25, 8))
plt.title("Traffic Volume Graph")
plt.xlabel("Date")
plt.ylabel("Traffic count")
plt.tight_layout()
plt.plot(df)

seasonal = df.iloc[:36]
plt.subplots(figsize=(25, 8))
plt.title("Traffic Volume Graph")
plt.xlabel("Date")
plt.ylabel("Traffic count")
plt.plot(seasonal)


# ### Model Fitting

def Holt_Winter(Data, Periods, Trend, Seasonal, Title):
    Holt_Winter = ExponentialSmoothing(Data, seasonal_periods = Periods, trend = Trend,
                                    seasonal = Seasonal).fit(use_boxcox=True)
    
    plt.subplots(figsize=(25, 8))
    plt.title(Title)
    plt.xlabel("Date")
    plt.ylabel("Passengers Count")
    
    Holt_Winter.fittedvalues.plot(color = "blue", marker = "o")
    Holt_Winter.forecast(36).plot(style = "--", marker = "o", color  = "red",
                           label = "Forecast", legend = True)


# ### Full Data

# +
import warnings
warnings.filterwarnings('ignore')

Holt_Winter(df, 12, "additive", "additive",
            "Forcasted Full Data")
# -

# ### Data Train

Holt_Winter(train, 12, "additive", "additive",
            "Forcasted Train Data")

# ### Data Test

Holt_Winter(test, 12, "additive", "additive",
            "Forcasted Test Data")

# ### Comparing and Error Checking

# +
fit_train = ExponentialSmoothing(train, seasonal_periods = 12, trend = "additive", seasonal = "additive").fit(use_boxcox=True)

plt.subplots(figsize=(25, 8))
plt.title("Comparing Forcasted Train Data and The Original Data")
plt.xlabel("Date")
plt.ylabel("Passengers Count")
plt.plot(df)
fit_train.fittedvalues.plot(color = "green", marker = "o")
forcasting = fit_train.forecast(24)
forcasting.plot(style = "--", marker = "o", color  = "red", label = "Forecast", legend = True)
# -

# ### Evaluation

mse = mean_squared_error(for_comparing, forcasting)
print('Mean squared error:', mse)
#Calculating MAE
mae = mean_absolute_error(for_comparing, forcasting)
print('Mean absolute error:', mae)
#Calculating RMSE
rmse = np.sqrt(mse)
print('Root Mean Squared Error:', rmse)

StarcoderdataJupyterScriptsDedupFiltered