In this notebook, we'll do some quick exploratory analysis on the COMBED data set
In [1]:
from nilmtk import DataSet
Download the data set
In [94]:
!wget http://combed.github.io/downloads/combed.h5 /Users/nipunbatra/Desktop/combed.h5
In [2]:
ds = DataSet("/Users/nipunbatra/Desktop/combed.h5")
In [3]:
ds.metadata
Out[3]:
In [4]:
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 [5]:
elec = ds.buildings[1].elec
In [6]:
df = elec.energy_per_meter()
In [7]:
df
Out[7]:
In [8]:
df.ix['active'].plot(kind='bar');
Okay, with Mains up there, this does not look pretty! Let us compute this function only on the submeters.
In [9]:
df = elec.submeters().energy_per_meter()
In [10]:
df.ix['active'].plot(kind='barh')
labels = elec.get_labels(df.columns)
plt.yticks(range(len(df.columns)), labels);
Let us now zoom into individual floor energy consumption
In [11]:
from nilmtk import MeterGroup
floor_mg = MeterGroup([meter for meter in elec.meters if "name" in meter.metadata])
In [12]:
floor_mg
Out[12]:
In [13]:
floor_mg.plot()
Out[13]:
In [14]:
df_floor = floor_mg.energy_per_meter().ix['active']
df_floor.plot(kind='barh');
labels = elec.get_labels(df_floor.index)
plt.yticks(range(len(df_floor.index)), labels);
Let us now try and see if we can break down individual floor energy consumption once we have some training data.
In [15]:
from nilmtk.disaggregate import CombinatorialOptimisation, FHMM
from nilmtk.metrics import f1_score, error_in_assigned_energy, fraction_energy_assigned_correctly
In [16]:
split_point = elec.train_test_split(train_fraction=0.5)
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 [ ]: