In [1]:
import numpy as np
import pandas as pd
from os.path import join
from pylab import rcParams
import matplotlib.pyplot as plt
%matplotlib inline
rcParams['figure.figsize'] = (13, 6)
plt.style.use('ggplot')
import nilmtk
from nilmtk import DataSet, TimeFrame, MeterGroup, HDFDataStore
from nilmtk.disaggregate import CombinatorialOptimisation, fhmm_exact
from nilmtk.utils import print_dict
from nilmtk.metrics import f1_score
import warnings
warnings.filterwarnings("ignore")
The full data set can be downloaded from the remote WikiEnergy database. The credentials are omitted here for security reasons.
In [2]:
# download_wikienergy(database_username, database_password, hdf_filename)
In [3]:
data_dir = '/Users/nipunbatra/Downloads/'
we = DataSet(join(data_dir, 'wikienergy.h5'))
print('loaded ' + str(len(we.buildings)) + ' buildings')
In [4]:
building_number = 11
print_dict(we.buildings[building_number].metadata)
In [5]:
elec = we.buildings[building_number].elec
elec.appliances
Out[5]:
In [6]:
elec.draw_wiring_graph();
In [7]:
we.set_window(start='2014-04-01 00:00:00', end='2014-04-02 00:00:00')
elec.plot();
In [8]:
elec.mains().good_sections()
Out[8]:
In [9]:
# Train
co = CombinatorialOptimisation()
co.train(elec)
In [10]:
# Disaggregate
disag_filename = join(data_dir, 'wikienergy-disag-co.h5')
output = HDFDataStore(disag_filename, 'w')
co.disaggregate(elec.mains(), output)
output.close()
In [11]:
%%capture
# Train
fhmm = fhmm_exact.FHMM()
fhmm.train(elec)
# Disaggregate
disag_filename = join(data_dir, 'wikienergy-disag-fhmm.h5')
output = HDFDataStore(disag_filename, 'w')
fhmm.disaggregate(elec.mains(), output)
output.close()
In [12]:
disag_filename = join(data_dir, 'wikienergy-disag-co.h5')
disag = DataSet(disag_filename)
disag_elec = disag.buildings[building_number].elec
disag_elec.plot()
disag.store.close()
plt.title("CO");
In [13]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[building_number].elec
f1 = f1_score(disag_elec, elec)
f1.index = disag_elec.get_labels(f1.index)
f1.plot(kind='barh')
plt.ylabel('appliance');
plt.xlabel('f-score');
plt.title("CO");
disag.store.close()
In [14]:
disag_filename = join(data_dir, 'wikienergy-disag-fhmm.h5')
disag = DataSet(disag_filename)
disag_elec = disag.buildings[building_number].elec
disag_elec.plot()
plt.title("FHMM");
disag.store.close()
In [15]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[building_number].elec
f1 = f1_score(disag_elec, elec)
f1.index = disag_elec.get_labels(f1.index)
f1.plot(kind='barh')
plt.ylabel('appliance');
plt.xlabel('f-score');
plt.title("FHMM");
disag.store.close()
In [17]:
# CSS styling
from IPython.core.display import display, HTML
display(HTML(open('static/styles.css', 'r').read()));