text_plain_output_3.png text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png
from plotly.offline import init_notebook_mode, iplot

import numpy as np

import pandas as pd

import plotly.graph_objs as go

import plotly.graph_objs as go

df = pd.read_csv('../input/PJME_hourly.csv', index_col=[0], parse_dates=[0])

import plotly.graph_objs as go
trace1 = go.Scatter(x=df.index, y=df.PJME_MW)
data = [trace1]
fig = dict(data=data)

splitdate = '2014-01-01'
df_train_set = df[df.index < splitdate]
df_test_set = df[df.index > splitdate]

trace1 = go.Scatter(x=df_train_set.index, y=df_train_set.PJME_MW)
data = [trace1]
fig = dict(data=data)

trace1 = go.Scatter(x=df_test_set.index, y=df_test_set.PJME_MW)
data = [trace1]
fig = dict(data=data)

def AddDateProperties(df):
    df['date'] = df.index
    df['hour'] = df['date'].dt.hour
    df['dayofweek'] = df['date'].dt.dayofweek
    df['quarter'] = df['date'].dt.quarter
    df['month'] = df['date'].dt.month
    df['year'] = df['date'].dt.year
    df['dayofyear'] = df['date'].dt.dayofyear
    df['dayofmonth'] = df['date'].dt.day
    df['weekofyear'] = df['date'].dt.weekofyear
    return df

df_test_set = AddDateProperties(df_test_set)
df_train_set = AddDateProperties(df_train_set)
df_test_set = df_test_set.drop(['date'], axis=1)
df_train_set = df_train_set.drop(['date'], axis=1)
y_test = df_test_set['PJME_MW']
y_train = df_train_set['PJME_MW']
X_test = df_test_set.loc[:, df_test_set.columns != 'PJME_MW']
X_train = df_train_set.loc[:, df_train_set.columns != 'PJME_MW']

df_test_set['AbsError'] = df_test_set.Error.apply(np.abs)

day_groupby = df_test_set.groupby(['year', 'month', 'dayofmonth'])
error_by_day = day_groupby['PJME_MW', 'MW_Prediction', 'Error', 'AbsError'].mean()

error_by_day.sort_values(ascending=True, by='AbsError').head(15)