-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_predictions.py
107 lines (86 loc) · 3.46 KB
/
make_predictions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# coding: utf-8
# In[6]:
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
from os.path import join
import os
import pandas as pd
from mylib import get_folders
def get_dataframe(folder, resultsdir, alphabet, klasses):
resultsdir = join(folder, resultsdir, 'alphabet_%s' % alphabet)
dfs = []
for kls in klasses:
csvf = join(resultsdir, 'class_%s.csv' % kls)
df = pd.DataFrame.from_csv(csvf, index_col=False)
if len(dfs):
del df['label']
dfs.append(df)
return pd.concat(dfs, axis=1)
def predict(df):
df['predicted'] = df.iloc[:, 1:].apply(lambda x: int(x.argmax()[len('score_class_'):]), axis=1)
return df
def process_results(folder, resultsdir):
for a in range(20, 21):
try:
clsssifiedf = join(folder, resultsdir, 'alphabet_%s' % a, 'classified.csv')
traincsv = join(folder, 'train', 'saxified_%s.csv' % a)
traindf = pd.DataFrame.from_csv(traincsv, index_col=False)
klasses = sorted(traindf['label'].unique())
df = get_dataframe(folder, resultsdir, a, klasses)
df = predict(df)
df.to_csv(clsssifiedf, index=False)
print folder, len(klasses), a, accuracy_score(df['label'].values.tolist(), df['predicted'].values.tolist())
# print classification_report(df['label'].values.tolist(), df['predicted'].values.tolist())
except Exception as e:
print e
pass
print
return
root = '/Users/daoyuan.li/Documents/Smart.Buildings/Dataset/DECC/popular_appliances/combinations/'
for folder in get_folders(root):
try:
process_results(folder, resultsdir='final_results_wl_2_to_20')
except:
print folder
# In[ ]:
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
from os.path import join
import os
import pandas as pd
from mylib import get_folders
def get_dataframe(folder, resultsdir, alphabet, klasses):
resultsdir = join(folder, resultsdir, 'alphabet_%s' % alphabet)
dfs = []
for kls in klasses:
csvf = join(resultsdir, 'class_%s.csv' % kls)
df = pd.DataFrame.from_csv(csvf, index_col=False)
if len(dfs):
del df['label']
dfs.append(df)
return pd.concat(dfs, axis=1)
def predict(df):
df['predicted'] = df.iloc[:, 1:].apply(lambda x: int(x.argmax()[len('score_class_'):]), axis=1)
return df
def process_results(folder, resultsdir):
for a in range(3, 21):
try:
clsssifiedf = join(folder, resultsdir, 'alphabet_%s' % a, 'classified.csv')
traincsv = join(folder, 'train', 'saxified_%s.csv' % a)
traindf = pd.DataFrame.from_csv(traincsv, index_col=False)
klasses = sorted(traindf['label'].unique())
df = get_dataframe(folder, resultsdir, a, klasses)
df = predict(df)
df.to_csv(clsssifiedf, index=False)
print folder, len(klasses), a, accuracy_score(df['label'].values.tolist(), df['predicted'].values.tolist())
# print classification_report(df['label'].values.tolist(), df['predicted'].values.tolist())
except Exception as e:
print e
print
return
root = '/Users/daoyuan.li/Documents/Smart.Buildings/Dataset/DECC/popular_appliances/combinations/'
for folder in get_folders(root):
try:
process_results(folder, resultsdir='final_results_wl_2_to_20')
except:
print folder