In [2]:
import data
import pandas as pd
In [3]:
mydata = data.alldata.copy()
mydata
Out[3]:
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]:
In [13]:
reg2 = tree.DecisionTreeClassifier()
reg2.fit(x3,y2)
reg2.score(x3,y2)
Out[13]:
In [14]:
reg3 = tree.DecisionTreeClassifier()
reg3.fit(x3,y3)
reg3.score(x3,y3)
Out[14]:
In [15]:
reg4 = tree.DecisionTreeClassifier()
reg4.fit(x3,y4)
reg4.score(x3,y4)
Out[15]:
In [16]:
reg5 = tree.DecisionTreeClassifier()
reg5.fit(x3,y5)
reg3.score(x3,y5)
Out[16]:
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))
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 [ ]: