In [1]:
from nilmtk import *
from nilmtk.disaggregate import fhmm_exact
In [2]:
import time
In [3]:
train = DataSet('/data/REDD/redd.h5')
test = DataSet('/data/REDD/redd.h5')
In [4]:
building = 2
train.set_window(end="30-4-2011")
test.set_window(start="30-4-2011")
In [5]:
train_elec = train.buildings[building].elec
test_elec = test.buildings[building].elec
In [6]:
%matplotlib inline
In [7]:
train_elec.plot()
Out[7]:
In [8]:
test_elec.plot()
Out[8]:
In [10]:
start = time.time()
fhmm = fhmm_exact.FHMM()
fhmm.train(train_elec, sample_period=120)
end = time.time()
print("Runtime =", end-start, "seconds.")
In [11]:
import pandas as pd
import numpy as np
In [12]:
pred = {}
gt= {}
for i, chunk in enumerate(test_elec.mains().load(sample_period=120)):
chunk_drop_na = chunk.dropna()
pred[i] = fhmm.disaggregate_chunk(chunk_drop_na)
gt[i]={}
for meter in test_elec.submeters().meters:
# Only use the meters that we trained on (this saves time!)
gt[i][meter] = meter.load(sample_period=120).next()
gt[i] = pd.DataFrame({k:v.squeeze() for k,v in gt[i].iteritems()}, index=gt[i].values()[0].index).dropna()
In [13]:
# If everything can fit in memory
gt_overall = pd.concat(gt)
gt_overall.index = gt_overall.index.droplevel()
pred_overall = pd.concat(pred)
pred_overall.index = pred_overall.index.droplevel()
# Having the same order of columns
gt_overall = gt_overall[pred_overall.columns]
In [14]:
%matplotlib inline
In [15]:
gt_overall.plot()
Out[15]:
In [16]:
pred_overall = pred_overall.ix[gt_overall.index]
gt_overall = gt_overall.ix[pred_overall.index]
In [17]:
from sklearn.metrics import mean_squared_error
In [18]:
rmse={}
for col in pred_overall.columns:
rmse[col] = np.sqrt(mean_squared_error(gt_overall[col], pred_overall[col]))
In [20]:
pd.Series(rmse).plot(kind="barh")
Out[20]:
In [ ]: