In [1]:
from __future__ import print_function, division
import pandas as pd
import numpy as np
from copy import deepcopy
from os.path import join, isdir, isfile, dirname, abspath
from os import listdir, getcwd
import re
from sys import stdout, getfilesystemencoding
from nilmtk.datastore import Key
from nilmtk.timeframe import TimeFrame
from nilmtk.measurement import LEVEL_NAMES
from nilm_metadata import convert_yaml_to_hdf5
from inspect import currentframe, getfile, getsourcefile
from copy import copy
In [2]:
import matplotlib.pyplot as plt
In [3]:
from nilmtk import DataSet, TimeFrame
from nilmtk.disaggregate import CombinatorialOptimisation
In [4]:
train = DataSet("/home/nipun/Desktop/redd.h5")
test = copy(train)
In [5]:
elec = train.buildings[2].elec
In [6]:
building_2 = train.buildings[2]
In [7]:
elec.map_meter_instances_to_appliance_ids()
Out[7]:
Finding top-k appliances for training
In [25]:
top_k = elec.select_top_k(k=6)
In [26]:
top_k
Out[26]:
In [27]:
elec.energy_per_meter().T
Out[27]:
In [28]:
split_point = elec.train_test_split(0.5)
In [29]:
split_point
Out[29]:
In [30]:
elec.good_sections()
Out[30]:
In [31]:
train.store.window = TimeFrame(start=None, end = split_point)
test.store.window = TimeFrame(start=split_point, end=None)
In [32]:
from nilmtk import DataSet, TimeFrame
from nilmtk.disaggregate import CombinatorialOptimisation
In [33]:
co = CombinatorialOptimisation()
In [34]:
co.train(top_k)
In [35]:
co.model
Out[35]:
In [36]:
from nilmtk import HDFDataStore
output = HDFDataStore('output.h5', 'w')
test_mains = test.buildings[2].elec.mains()
co.disaggregate(test_mains, output)
In [37]:
output.store.keys()
Out[37]:
In [38]:
%matplotlib inline
In [39]:
fig, ax = plt.subplots(nrows=2, sharex=True)
output.store['/building2/elec/meter9'][:'May 3 2011'].plot(label='Predicted', ax=ax[0])
train.buildings[2].elec['fridge'].power_series_all_data()[:'May 3 2011'].plot(ax=ax[1])
plt.legend()
Out[39]:
In [41]:
output.store['fridge']
In [ ]: