Power Consumption Analysis and Forecasting: Part 2, Forecasting

Overview

Background

  • We are asked to perform an in-depth analysis and forecasting of the power consumption dataset for a sub-metering company. We accomplished this via data visualization and time series regression modeling.
  • This file contains Part 2, Forecasting.

Objective

  • Empower Smart Home owners with greater understanding and control of their power usage.
  • Reach the developer’s goal of offering highly efficient Smart Homes that providing owners with power usage analytics.
  • Provide accurate energy monitoring and forecasting for the utility company.

Dataset Information

  • The data was gathered in a house located in Sceaux, France. It contains the measurements of electric power consumption from 3 sub-meters in the household with a one-minute sampling rate over the period of almost 4 years.
  • We collected the data from UC Irvine machine learning repository. It was stored on Amazon Web Service with a password to access for security.
  • Sub-meters Information
    • Sub-metering 1, Kitchen(a dishwasher, an oven and a microwave).
    • Sub-metering 2, Laundry room(a washing-machine, a tumble-drier, a refrigerator and a light).
    • Sub-metering 3, Electric water-heater and an air-conditioner.

Data Science, Forecasting Process

Dataset has been cleaned and pre-processed in the previous step (Power Consumption Visualization and Analysis).

Time Series Linear Model

  • The time series data is often considered with the aim of forecasting the future. What we need to predict is continuous data, so we used linear regression for our prediction.
  • We created three different time series linear models for three different time periods.
  • We used the tslm() function to build the models and forecast() functions to make the forecastings.
  • A common property of time series data is trend, so here we will include trend in our model.
  • Our data also showed strong seasonality from the previous analysis, hence, we also include season property in our model building process.
  • For the plot, we limited y axis starting from 0 since there won’t be negative values for power consumption.
# load forecast package
library(forecast)
# Apply time series linear regression to the sub-meter 3 time-series object with trand and season properties. 
fitSM3 <- tslm(tsSM3_070809weekly ~ trend + season) 
# Create the forecast for sub-meter 3. Forecast ahead 20 time periods(weeks), with a confidence levels 80 and 90.
forecastfitSM3c <- forecast(fitSM3, h=20, level=c(80,90))
## Plot sub-meter 3 forecast, limit y and add labels
plot(forecastfitSM3c, ylim = c(0, 20), ylab= "Watt-Hours", xlab="Time",
     main = "Sub-meter 3 Forecast, Mondays, 20:00 ")

# Forecast of Sub-meter 1 for the first 20 weeks at 8pm of 2010.
fitSM1 <- tslm(tsSM1_070809weeklySat20 ~ trend + season)
forecastfitSM1 <- forecast(fitSM1, h = 20, level = c(80,90))
plot(forecastfitSM1, ylim = c(0, 70), ylab = "Watt-Hours", xlab = "Time",
     main = "Sub-meter 1 Forecast, Saturdays, 20:00 ")

# Forecast of Sub-meter 2 for the first week of June, 2007.. 
fitSM2 <- tslm(tsSM2_07Monthly ~ trend + season)
forecastfitSM2 <- forecast(fitSM2, h = 168, level = c(80, 90))
plot(forecastfitSM2, ylim = c(0, 40), ylab = "Watt-Hours", xlab = "Time",
     main = "Sub-meter 2 Forecast, First Week of Jun, 2007")

Decomposing a Seasonal Time Series

  • In order to analyze the trend of a time series independently of the seasonal components, we removed the seasonal component of the time series that exhibits in the seasonal pattern.
  • In order to correctly estimate any trend and seasonal components that might be in the time series, we used the decompose() function in the forecast package, which estimates the trend, seasonal, and irregular components of a time series.
# Decompose Sub-meter 3 into trend, seasonal and random
components070809SM3weekly <- decompose(tsSM3_070809weekly)
## Plot decomposed sub-meter 3 
plot(components070809SM3weekly)

  • Decomposition of Sub-meter 3(Water Heater & AC) at 20:00 on Mondays from 2007 to 2009.
  • Trend component shows the power consumption was the lowest during 2009, it started to go up again since 2009.
# Sub-meter 1 decomposition and the plot
components070809SM1weekly <- decompose(tsSM1_070809weeklySat20)
plot(components070809SM1weekly)

  • Decomposition of Sub-meter 1(Kitchen) at 20:00 on Saturdays from 2007 to 2009.
  • Trend component shows the power consumption went up since the second half of 2008.
# Sub-meter 2 decomposition and the plot
components07SM2monthly <- decompose(tsSM2_07Monthly)
plot(components07SM2monthly)

  • Decomposition of Sub-meter 2(Laundry Room) power consumption in May, 2007.
  • Decomposition shows a clear daily seasonality.

Holt-Winters Forecasting Since our data has trend and seasonal components, here we are going to try anoter way to make time series forecasting.

  • To make forecasts using exponential smoothing, we can fit an exponential smoothing predictive model using the HoltWinters() function from the stats package.
  • First, we did seasonal adjusting. We removed the seasonal component that we identified via decomposition.
  • We decomposed again to see if the seasonal component was removed.
  • Then we use HoltWinters() function to fit the model. We created three different models for three different time periods. We kept beta and gamma as TRUE since there are trend and seasonality in the data.
  • Last, we made the forecast using forecast() function and made the plots.
# Seasonal adjusting sub-meter 3 by subtracting the seasonal component
tsSM3_070809Adjusted <- tsSM3_070809weekly - components070809SM3weekly$seasonal
# Test Seasonal Adjustment by running Decompose again
plot(decompose(tsSM3_070809Adjusted))

# Holt Winters Exponential Smoothing
tsSM3_HW070809 <- HoltWinters(tsSM3_070809weekly)
# Forecast HoltWinters with confidence levels
tsSM3_HW070809for <- forecast(tsSM3_HW070809, h=25, level=c(85,95))
# Plot only the forecasted area
plot(tsSM3_HW070809for, ylim = c(0, 30), ylab= "Watt-Hours", xlab="Time - Sub-meter 3",
     start(2010), main = "Sub-meter 3 HWForecast, Mondays, 20:00")

  • The scale for the seasonal section is from -1e-15 through 5e-16. For all practical purposes the seasonality has been removed.

  • Sub-meter 3(Water Heater & AC) forecasting for the first 25 weeks on Mondays at 20:00 for 2010.
# Sub_meter 1
tsSM1_070809Adjusted <- tsSM1_070809weeklySat20 - components070809SM1weekly$seasonal
tsSM1_HW070809 <- HoltWinters(tsSM1_070809Adjusted)
tsSM1_HW070809for <- forecast(tsSM1_HW070809, h=25, level=c(85,95))
plot(tsSM1_HW070809for, ylim = c(0, 60), ylab= "Watt-Hours", xlab="Time - Sub-meter 1", 
     start(2010), main = "Sub-meter 1 HWForecast, Saturdays, 20:00")

  • Sub-meter 1(Kitchen) forecasting for the first 25 weeks on Saturdays at 18:00 for 2010.
# Sub_meter 2
tsSM2_07Adjusted <- tsSM2_07Monthly - components07SM2monthly$seasonal
tsSM2_HW07 <- HoltWinters(tsSM2_07Adjusted)
tsSM2_HW07for <- forecast(tsSM2_HW07, h=24, level=c(85,95))
plot(tsSM2_HW07for, ylim = c(0, 20), ylab= "Watt-Hours", xlab="Time - Sub-meter 2",
     start(30), main = "Sub-meter 2 HWForecast, May, 2007")

  • Sub-meter2(Laundry) forecasting for the first week for June, 2007.

Data Insights and Suggestions

  • AC power consumption appears to peak around noon. Suggest to turn the temperature higher when leaving home.
  • There is a trend going down in 2008 for the Water Heater & AC consumption. Suggest to investigate the reasons and maybe there is possibility to save power in the future.
  • Power consumption in the kitchen varies, probably due to dishwasher usage.
  • Suggest to add outdoor temperature to the dataset, so that we can get insights according to the outdoor temperature changes.

Business Recommendation for the Sub-metering Company

  • Separate Water Heater and AC to two different sub-meters, so it’ll be more explicit for either homeowner or the utility company to understand the two most power consuming appliances.
  • Generate the consumption comparison of the current month and the previous month to help homeowner understand what behaviors could lead to less power usage.
  • Develop a reminder system to remind homeowner when the power consumption reaches certain amount.
  • Develop an app that homeowner can monitor the power consumption when they want to. For example, how much more power it’ll use if patio door is left open when the AC is on?
  • Generate how much power it has saved by using sub-meters for the utility company.