text_html_output_1.png
from sklearn.metrics import mean_squared_error, mean_absolute_percentage_error

import math

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df = pd.read_csv('/kaggle/input/johnson/Johnson.csv')
df.drop('Unnamed: 0', axis=1, inplace=True)
train_df = df[df['time'] < 1980]
test_df = df[df['time'] >= 1980]

def Arith_mean(ser):
    mean = ser.mean()
    test = test_df.copy()
    test['value'] = mean
    return test
arith_test = Arith_mean(train_df['value'])
arith_test

def last_record(ser):
    last = ser.tail(1)
    
    test = test_df.copy()
    
    test['value'] = float(last)
    
    return test
    
last_record_test = last_record(train_df['value'])
last_record_test

def last_4_quarter(ser):
    test = test_df.copy()
    
    test['value'] = ser.tail(4)['value'].unique()
    
    return test
    
last_4_quarter_test = last_4_quarter(train_df)
last_4_quarter_test

arith_test_mape = mean_absolute_percentage_error(test_df['value'], arith_test['value'])
arith_test_mse = mean_squared_error(test_df['value'], arith_test['value'])
arith_test_rmse = math.sqrt(arith_test_mse)
last_record_test_mape = mean_absolute_percentage_error(test_df['value'], last_record_test['value'])
last_record_test_mse = mean_squared_error(test_df['value'], last_record_test['value'])
last_record_test_rmse = math.sqrt(last_record_test_mse)
last_4_quarter_test_mape = mean_absolute_percentage_error(test_df['value'], last_4_quarter_test['value'])
last_4_quarter_test_mse = mean_squared_error(test_df['value'], last_4_quarter_test['value'])
last_4_quarter_test_rmse = math.sqrt(last_4_quarter_test_mse)

import matplotlib.pyplot as plt

def create_bar_graph(values, labels=['arith_mean', 'latest_record', 'last_4_record']):
    """
    Create a bar graph for three values.

    Arguments:
    labels -- a list of labels for each value
    values -- a list of three numerical values
    """
    # Create a figure and axis
    fig, ax = plt.subplots()

    # Create a bar plot
    ax.bar(labels, values)

    # Add labels and title
    ax.set_xlabel('Categories')
    ax.set_ylabel('Values')
    ax.set_title('Bar Graph')

    # Display the plot
    plt.show()
    
def create_list(var1, var2, var3):
    """
    Create a list from three variables.

    Arguments:
    var1 -- the first variable
    var2 -- the second variable
    var3 -- the third variable

    Returns:
    A list containing var1, var2, and var3.
    """
    return [var1, var2, var3]

create_bar_graph(create_list(arith_test_mape, last_record_test_mape, last_4_quarter_test_mape))