In [2]:
import data
import pandas as pd

In [3]:
mydata = data.alldata.copy()
mydata


Out[3]:
mains television fan fridge laptop computer electric heating element oven unknown washing machine microwave toaster sockets cooker Kitchen LivingRoom StoreRoom Room1 Room2
2015-07-05 00:00:03 0.0 0.0 0.00 0.000000 0.000000 0.00 0.0 0.0 0.00 0.00 0.0 0.00 0.0 1 0 0 0 0
2015-07-05 00:00:04 0.0 0.0 0.00 0.000000 0.000000 0.00 0.0 0.0 0.00 0.00 0.0 0.00 0.0 0 0 0 0 0
2015-07-05 00:00:05 0.0 0.0 0.00 0.000000 0.000000 0.00 0.0 0.0 0.00 0.00 0.0 0.00 0.0 0 0 0 0 0
2015-07-05 00:00:06 0.0 0.0 0.00 0.000000 0.000000 0.00 0.0 0.0 0.00 0.00 0.0 0.00 0.0 0 0 0 0 0
2015-07-05 00:00:07 0.0 0.0 0.00 0.000000 0.000000 0.00 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 1 0 0 0
2015-07-05 00:00:08 223.0 0.0 0.00 99.210000 0.000000 0.00 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 1 0 1
2015-07-05 00:00:09 223.6 0.0 0.00 99.179070 28.340000 0.00 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 1 0 0 0
2015-07-05 00:00:10 224.2 0.0 0.00 99.148140 28.378095 0.00 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 1 0 0 0
2015-07-05 00:00:11 224.8 0.0 0.00 99.117209 28.416190 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 1 0 0 0 0
2015-07-05 00:00:12 225.4 0.0 0.00 99.086279 28.454286 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:13 226.0 0.0 0.00 99.055349 28.492381 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:14 226.6 0.0 0.00 99.024419 28.530476 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:15 227.2 0.0 0.00 98.993488 28.568571 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:16 227.8 0.0 0.00 98.962558 28.606667 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:17 228.4 0.0 0.00 98.931628 28.644762 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:18 229.0 0.0 0.00 98.900698 28.682857 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:19 226.1 0.0 0.00 98.869767 28.720952 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:20 223.2 0.0 0.00 98.838837 28.759048 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:21 220.3 0.0 0.00 98.807907 28.797143 2.29 0.0 0.0 0.00 0.00 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:22 217.4 0.0 29.65 98.776977 28.835238 2.29 0.0 0.0 0.00 1.24 0.0 7.35 0.0 0 0 1 1 0
2015-07-05 00:00:23 214.5 0.0 29.65 98.746047 28.873333 2.29 0.0 0.0 0.00 1.24 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:24 211.6 0.0 29.65 98.715116 28.911429 2.29 0.0 0.0 0.00 1.24 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:25 208.7 0.0 29.65 98.684186 28.949524 2.29 0.0 0.0 0.00 1.24 0.0 7.35 0.0 1 0 0 0 0
2015-07-05 00:00:26 205.8 0.0 29.65 98.653256 28.987619 2.29 0.0 0.0 0.68 1.24 0.0 7.35 0.0 1 0 0 0 0
2015-07-05 00:00:27 202.9 0.0 29.65 98.622326 29.025714 2.29 0.0 0.0 0.68 1.24 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:28 200.0 0.0 29.65 98.591395 29.063810 2.29 0.0 0.0 0.68 1.24 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:29 199.9 0.0 29.65 98.560465 29.101905 2.29 0.0 0.0 0.68 1.24 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:30 199.8 0.0 29.65 98.529535 29.140000 2.29 0.0 0.0 0.68 1.24 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:31 199.7 0.0 29.65 98.498605 29.178095 2.29 0.0 0.0 0.68 1.24 0.0 7.35 0.0 0 0 0 0 0
2015-07-05 00:00:32 199.6 0.0 29.65 98.467674 29.216190 2.29 0.0 0.0 0.68 1.24 0.0 7.35 0.0 0 0 0 0 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2015-12-05 21:54:46 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:47 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:48 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:49 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:50 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:51 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:52 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:53 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:54 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:55 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:56 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:57 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:58 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:54:59 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:00 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:01 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:02 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:03 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:04 0.0 0.0 0.00 0.000000 17.400000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:05 0.0 0.0 0.00 0.000000 16.675000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:06 0.0 0.0 0.00 0.000000 15.950000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:07 0.0 0.0 0.00 0.000000 15.225000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:08 0.0 0.0 0.00 0.000000 14.500000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:09 0.0 0.0 0.00 0.000000 13.775000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:10 0.0 0.0 0.00 0.000000 13.050000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:11 0.0 0.0 0.00 0.000000 12.325000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:12 0.0 0.0 0.00 0.000000 11.600000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:13 0.0 0.0 0.00 0.000000 10.875000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:14 0.0 0.0 0.00 0.000000 10.150000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 0 0 0 0
2015-12-05 21:55:15 0.0 0.0 0.00 0.000000 9.425000 2.55 0.0 0.0 0.95 1.24 0.0 1.39 0.0 0 1 0 0 0

13298113 rows × 18 columns


In [4]:
from sklearn import tree
import matplotlib.pyplot as plt
import datetime as dt
import numpy as np

mydata1 = mydata.copy()
x3 = mydata1[['television','fan','fridge','laptop computer','electric heating element','oven','unknown','washing machine','microwave','toaster','sockets','cooker']]
#xrange = np.arange(x3.min(),x3.max(),(x3.max()-x3.min())/100).reshape(100,1)
y1 = mydata1['Kitchen'].astype(float)
y2 = mydata1['LivingRoom'].astype(float)
y3 = mydata1['StoreRoom'].astype(float)
y4 = mydata1['Room1'].astype(float)
y5 = mydata1['Room2'].astype(float)

In [12]:
reg1 = tree.DecisionTreeClassifier() 
reg1.fit(x3,y1)
reg1.score(x3,y1)


Out[12]:
0.99998962258780622

In [13]:
reg2 = tree.DecisionTreeClassifier() 
reg2.fit(x3,y2)
reg2.score(x3,y2)


Out[13]:
0.99996856696886238

In [14]:
reg3 = tree.DecisionTreeClassifier() 
reg3.fit(x3,y3)
reg3.score(x3,y3)


Out[14]:
0.99999563847893302

In [15]:
reg4 = tree.DecisionTreeClassifier()
reg4.fit(x3,y4)
reg4.score(x3,y4)


Out[15]:
0.99999984960272181

In [16]:
reg5 = tree.DecisionTreeClassifier()
reg5.fit(x3,y5)
reg3.score(x3,y5)


Out[16]:
0.99992623013505755

In [18]:
#store_power = mydata[['television', 'fan', 'fridge', 'laptop computer','electric heating element', 'oven', 'unknown', 'washing machine', 'microwave', 'toaster', 'sockets', 'cooker']]
#store_occupancy = mydata[['StoreRoom']]

x3 = x3.as_matrix()
x3 = x3[:13298110]
y1 = y1.as_matrix()
y1 = y1[:13298110]
y2 = y2.as_matrix()
y2 = y2[:13298110]
y3 = y3.as_matrix()
y3 = y3[:13298110]
y4 = y4.as_matrix()
y4 = y4[:13298110]
y5 = y5.as_matrix()
y5 = y5[:13298110]

from sklearn.model_selection import KFold, cross_val_score
from sklearn.metrics import accuracy_score

a = tree.DecisionTreeClassifier(max_depth=10)
a = a.fit(x3, y1)

kf = KFold(n_splits=10)

#for train_indices, test_indices in kf.split(store_power):
#    print('Train: %s | test: %s' % (train_indices, test_indices))
#    print(len(train_indices))
#    print(len(test_indices))

b=[]
#for train, test in kf.split(store_power):
#    a = a.fit(store_power[train], store_occupancy[train])
#    b.append(accuracy_score(store_occupancy[test],a.predict(store_power[test])))

b = [a.fit(x3[train], y1[train]).score(x3[test], y1[test]) for train, test in kf.split(x3)]
b
print(sum(b))


9.99752295627

In [8]:
x3 = x3.as_matrix()
x3 = x3[:13298110]
y2 = y2.as_matrix()
y2 = y2[:13298110]
y3 = y3.as_matrix()
y3 = y3[:13298110]
y4 = y4.as_matrix()
y4 = y4[:13298110]
y5 = y5.as_matrix()
y5 = y5[:13298110]

In [ ]:
from sklearn.model_selection import KFold, cross_val_score
from sklearn.metrics import accuracy_score
a = tree.DecisionTreeClassifier(max_depth=10)
a = a.fit(x3, y2)

kf = KFold(n_splits=10)
b=[]
b = [a.fit(x3[train], y2[train]).score(x3[test], y2[test]) for train, test in kf.split(x3)]
print(sum(b))
b

In [ ]:
a = tree.DecisionTreeClassifier(max_depth=10)
a = a.fit(x3, y3)

kf = KFold(n_splits=10)
c=[]
c = [a.fit(x3[train], y3[train]).score(x3[test], y3[test]) for train, test in kf.split(x3)]
print(sum(c))
c

In [ ]:
a = tree.DecisionTreeClassifier(max_depth=10)
a = a.fit(x3, y4)

kf = KFold(n_splits=10)
d=[]
d = [a.fit(x3[train], y4[train]).score(x3[test], y4[test]) for train, test in kf.split(x3)]
print(sum(d))
d

In [ ]:
a = tree.DecisionTreeClassifier(max_depth=10)
a = a.fit(x3, y5)

kf = KFold(n_splits=10)
e=[]
e = [a.fit(x3[train], y5[train]).score(x3[test], y5[test]) for train, test in kf.split(x3)]
print(sum(e))
e

In [ ]: