In this notebook, we'll do some quick exploratory analysis on the COMBED data set
In [2]:
from nilmtk import DataSet
Download the data set
In [3]:
train = DataSet("/Users/nipunbatra/Desktop/combed.h5")
test = DataSet("/Users/nipunbatra/Desktop/combed.h5")
In [4]:
train.set_window(end="16-6-2014")
test.set_window(start="16-6-2014")
In [5]:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import seaborn as sns
sns.set_style('white')
%matplotlib inline
import seaborn as sns
from matplotlib import rcParams
rcParams['figure.figsize'] = (16, 8)
In [6]:
from nilmtk.disaggregate import FHMM, CombinatorialOptimisation
In [7]:
train_elec = train.buildings[1].elec
In [9]:
mg_ahu = train_elec.select_using_appliances(type='AHU')
In [10]:
mg_ahu
Out[10]:
In [11]:
f = FHMM()
f.train(mg_ahu)
In [12]:
disag_filename = '/Users/nipunbatra/Desktop/disag-fhmm-ahu.h5'
from nilmtk import HDFDataStore
output = HDFDataStore(disag_filename, 'w')
mains = train_elec.mains()
f.disaggregate(mains, output)
In [13]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[1].elec
#disag_elec[(7)].plot()
#elec[7].plot()
#plt.tight_layout()
#disag.store.close()
In [25]:
disag_elec[('AHU', 1)].plot()
train_elec[('AHU', 1)].plot();
In [27]:
disag_elec[('AHU', 2)].plot()
train_elec[('AHU', 2)].plot();
In [28]:
disag_elec[('AHU', 3)].plot()
train_elec[('AHU', 3)].plot();
In [29]:
disag_elec[('AHU', 4)].plot()
train_elec[('AHU', 4)].plot();
In [39]:
from nilmtk.metrics import f1_score, fraction_energy_assigned_correctly, mean_normalized_error_power, rms_error_power
In [35]:
f1 = f1_score(disag_elec, train_elec)
f1.index = disag_elec.get_labels(f1.index)
f1.plot(kind='bar')
plt.xlabel('appliance');
plt.ylabel('f-score');
In [36]:
mean_normalized_error_power(disag_elec, train_elec)
Out[36]:
In [38]:
fraction_energy_assigned_correctly(disag_elec, train_elec)
In [41]:
rms_error_power(disag_elec, train_elec)
Out[41]:
In [20]:
c = CombinatorialOptimisation()
c.train(mg_ahu)
In [22]:
c.model
Out[22]:
Let us now try and see if we can break down individual floor energy consumption once we have some training data.
In [5]:
from nilmtk.disaggregate import Hart85
In [10]:
elec.load(resample = True, sample_period=240).next()
Out[10]:
In [6]:
h = Hart85()
In [21]:
h.train(elec.mains(), buffer_size=50, resample = True, sample_period=60 )
In [22]:
h.centroids.sort()
Out[22]:
In [23]:
h.steady_states
Out[23]:
In [15]:
mains_df = elec.mains().load(cols=[('power','active')], resample = True, sample_period=240).next()
In [16]:
ax = mains_df.plot()
h.steady_states['active average'].plot(style='ko', ax = ax);
In [54]:
%matplotlib osx
#sns.set_palette("Set1", n_colors=12)
ax = elec.mains().plot()
h.steady_states['active average'].plot(style='o', ax = ax);
plt.ylabel("Power (W)")
plt.xlabel("Time");
In [11]:
disag_filename = '/Users/nipunbatra/Desktop/disag.h5'
from nilmtk import HDFDataStore
output = HDFDataStore(disag_filename, 'w')
mains = elec.mains()
h.disaggregate(mains, output)
In [12]:
output.close()
In [13]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[1].elec
In [14]:
disag_elec
Out[14]:
In [18]:
fig, ax = plt.subplots(nrows=2, sharex = True)
ax1 = disag_elec['unknown', 2].plot(ax=ax[0])
elec.submeters().plot(ax=ax[1])
plt.xlabel("Time");
In [38]:
fig, ax = plt.subplots(nrows=2, sharex = True)
ax1 = disag_elec['unknown', 12].plot(ax=ax[0])
elec.meters[6].plot(ax=ax[1])
plt.xlabel("Time");
In [51]:
%matplotlib osx
sns.set_palette(sns.color_palette("coolwarm", 7))
disag_elec.plot()
Out[51]:
In [52]:
disag_elec.plot()
Out[52]:
In [17]:
split_point
Out[17]:
In [18]:
from copy import copy, deepcopy
train = deepcopy(ds)
test = deepcopy(train)
In [19]:
train.set_window(end='2014-06-16 23:28:38')
test.set_window(start='2014-06-16 23:28:38')
In [20]:
ds.buildings[1].elec.plot();
In [21]:
train.buildings[1].elec.plot()
In [22]:
train.buildings[1].elec.meters[1].load(chunksize=100).next()
In [23]:
train.import_metadata(ds.store)
Out[23]:
In [24]:
train.set_window(end='2014-06-16 23:28:38')
In [25]:
train.buildings[1].elec.plot();
In [26]:
ds.buildings[1].elec.plot();
In [27]:
test.buildings[1].elec.meters[1].load(chunksize=100).next()
In [28]:
test.import_metadata(ds.store)
Out[28]:
In [29]:
test.buildings[1].elec.plot()
Out[29]:
In [30]:
test.set_window(start='2014-06-16 23:28:38')
In [31]:
test.buildings[1].elec.plot();
In [32]:
train.buildings[1].elec.plot();
Lets try again
In [33]:
ds_2 = DataSet("/Users/nipunbatra/Desktop/combed.h5")
tr_store = deepcopy(ds_2.store)
In [36]:
tr = deepcopy(ds_2)
tr.import_metadata(tr_store)
te = deepcopy(ds_2)
te.import_metadata(deepcopy(ds_2.store))
Out[36]:
In [37]:
tr.set_window(end='2014-06-16 23:28:38')
te.set_window(start='2014-06-16 23:28:38')
In [38]:
tr.buildings[1].elec.plot()
In [32]:
co = CombinatorialOptimisation()
co.train(floor_mg)
In [39]:
ds
Out[39]:
In [41]:
b=ds.buildings[1]
In [42]:
elec = train.buildings[1].elec
In [43]:
elec.plot()
Out[43]:
In [15]:
co.model
Out[15]:
In [71]:
from nilmtk import DataSet, TimeFrame, MeterGroup, HDFDataStore
disag_filename = "/Users/nipunbatra/Desktop/out_co.h5"
output = HDFDataStore(disag_filename, 'w')
co.disaggregate(elec.mains(), output)
output.close()
In [72]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[1].elec
disag_elec[(7)].plot()
elec[7].plot()
plt.tight_layout()
disag.store.close()
In [ ]:
HDFDataStore(disag_filename
In [30]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[1].elec
disag_elec.plot()
disag.store.close()
In [17]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[1].elec
disag_elec.plot()
disag.store.close()
In [31]:
e = elec.meters[1]
In [32]:
e.dominant_appliance().identifier.type
Out[32]:
In [33]:
disag_elec
Out[33]:
In [34]:
a = {2:None}
In [35]:
a =
In [18]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[1].elec
f1 = f1_score(disag_elec, elec)
f1.index = disag_elec.get_labels(f1.index)
f1.plot(kind='bar')
plt.xlabel('appliance');
plt.ylabel('f-score');
disag.store.close()
In [37]:
f1
Out[37]:
In [31]:
from nilmtk.metrics import error_in_assigned_energy, mean_normalized_error_power
In [32]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[1].elec
e = mean_normalized_error_power(disag_elec, elec)
disag.store.close()
In [34]:
e
Out[34]:
In [22]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[1].elec
#%matplotlib inline
disag_elec[(3)].plot()
elec[3].plot()
plt.tight_layout()
In [23]:
disag_elec[(4)].plot()
elec[4].plot()
plt.tight_layout()
In [52]:
elec[3].load().next()['power','active'].plot()
Out[52]:
In [24]:
elec[3].load().next()['power','active'].plot()
Out[24]:
In [25]:
df = elec[3].load().next()
In [59]:
df['power','active']['13-06-2014'].plot()
Out[59]:
In [64]:
plt.plot(df['power','active']['16-06-2014'].values)
#df['power','active']['15-06-2014'].plot()
plt.plot(df['power','active']['15-06-2014'].values)
plt.plot(df['power','active']['14-06-2014'].values)
plt.plot(df['power','active']['13-06-2014'].values)
Out[64]:
In [65]:
plt.plot(df['power','active']['16-06-2014'].values)
Out[65]:
In [28]:
#disag_elec[('AHU', 2)].plot()
elec[('AHU', 2)].plot()
Out[28]:
In [29]:
#disag_elec[('AHU', 3)].plot()
elec[('AHU', 3)].plot()
Out[29]:
In [30]:
#disag_elec[('sockets', 1)].plot()
elec[('sockets', 1)].plot()
Out[30]:
In [30]:
df = elec[('sockets',1)].load().next()
In [32]:
df2 = disag_elec[('sockets',1)].load().next()
In [35]:
from nilmtk.disaggregate import fhmm_exact
In [36]:
fh = fhmm_exact.FHMM()
In [37]:
fh.train(floor_mg)
In [38]:
disag_filename = "/Users/nipunbatra/Desktop/out_fhmm.h5"
output = HDFDataStore(disag_filename, 'w')
fh.disaggregate(elec.mains(), output)
output.close()
In [39]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[1].elec
e = mean_normalized_error_power(disag_elec, elec)
disag.store.close()
In [40]:
e
Out[40]:
In [42]:
e.plot(kind='bar')
Out[42]:
In [67]:
disag = DataSet(disag_filename)
disag_elec = disag.buildings[1].elec
disag_elec[(7)].plot()
elec[7].plot()
plt.tight_layout()
disag.store.close()
In [ ]: