forked from srikoushik3/GreenCity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-proc.py
110 lines (88 loc) · 2.88 KB
/
data-proc.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
107
108
109
110
# main libraries
import pandas as pd
import numpy as np
import time
# visual libraries
from matplotlib import pyplot as plt
from matplotlib.ticker import FuncFormatter
import seaborn as sns
from mpl_toolkits.mplot3d import Axes3D
plt.style.use('ggplot')
# sklearn libraries
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import normalize, StandardScaler
from sklearn.metrics import confusion_matrix,accuracy_score,precision_score,recall_score,f1_score,matthews_corrcoef,classification_report,roc_curve
from sklearn.externals import joblib
from sklearn.decomposition import PCA
def display_ghg(x, pos):
return '{:03.0f}'.format(x)
#Fetch the data
df = pd.read_csv('AnnualEnergyConsumption2016.csv')
print(df.head())
print(df.columns)
# Top 10 Address Graphs
# GHG vs. Address
formatter = FuncFormatter(display_ghg)
ghg_df = df.sort_values(by=['GHG Emissions(Kg)'], ascending=[0])
fig, ax = plt.subplots(figsize=(15, 10))
ax.yaxis.set_major_formatter(formatter)
ax.set_ylabel("GHG Emissions(Kg)")
ax.set_xlabel("Address")
ghg_df = ghg_df[:7]
print(ghg_df.head())
barlist=plt.bar(ghg_df['Address'], ghg_df['GHG Emissions(Kg)'])
plt.savefig('Plots/Top10Graphs/ghg.png')
plt.clf()
# Water Usage vs. Address
formatter = FuncFormatter(display_ghg)
ghg_df = df.sort_values(by=['Annual Flow (Mega Litres)'], ascending=[0])
ghg_df = ghg_df[:7]
fig, ax = plt.subplots(figsize=(15, 10))
ax.yaxis.set_major_formatter(formatter)
ax.set_ylabel("Water Usage (Mega Litres)")
ax.set_xlabel("Address")
print(ghg_df.head())
barlist=plt.bar(ghg_df['Address'], ghg_df['Annual Flow (Mega Litres)'])
plt.savefig('Plots/Top10Graphs/water.png')
plt.clf()
# Electricity vs. Address
formatter = FuncFormatter(display_ghg)
ghg_df = df.sort_values(by=['Electricity Quantity'], ascending=[0])
ghg_df = ghg_df[:7]
fig, ax = plt.subplots(figsize=(15, 10))
ax.yaxis.set_major_formatter(formatter)
ax.set_ylabel("Electricity(kWh)")
ax.set_xlabel("Address")
print(ghg_df.head())
'''
col_list = ['r','g', 'b', 'c', 'm', 'y', 'k']
ind = 0
row = 0
comment_color = dict()
#print(comment_color.keys())
#print(ghg_df['Comments'][row])
#print(ghg_df['Comments'][row] in comment_color.keys())
colors = []
for i in range(7):
print('index: ', i)
print(ghg_df.head())
print('Comment: ', ghg_df['Comments'][i])
test = ghg_df['Comments'][i] in comment_color.keys()
print(colors)
print(test)
if test:
print('in if', test)
key = ghg_df['Comments'][i]
cur_color = comment_color[key]
else:
cur_color = col_list[ind]
comment_color[ghg_df['Comments'][i]] = cur_color
ind = ind + 1
colors.append(cur_color)
'''
barlist = plt.bar(ghg_df['Address'], ghg_df['Electricity Quantity'], color=colors)
for i in range(len(barlist)):
barlist[i].set_color()
plt.savefig('Plots/Top10Graphs/electricity.png')
plt.clf()