text_html_output_1.png
from sklearn.metrics import mean_squared_error, mean_absolute_percentage_error

import math

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)

print(last_record_test_mape, last_record_test_mse, last_record_test_rmse)