-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmyMl.py
140 lines (91 loc) · 3.29 KB
/
myMl.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from flask import Flask
import ghhops_server as hs
import tensorflow as tf
import os
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import joblib
# function option 1
def RunPredictionOp1(constructionType,buildingType,location,area,floorCount):
#Load saved model
model = tf.keras.models.load_model('log\LearnModel_A.h5')
model.summary()
# Input 1 - Building Concstruction Type
# 0 - RC
# 1 - Steel Concrete
# 2 - Wood
# 3 - Wood Hybrid
#constructionType = 2
# Input 2 - building type is 0 or 1
#buildingType = 1
# Input 3 - location 0 - 5
#location = 3
# Input 4 - Total floor area
#area = 100.0
# Input 5 - floorCount usually between 5 and 25
#floorCount = 10
# Create 2d numpy array
inputData = np.array([[constructionType], [buildingType], [location], [area], [floorCount]])
#pathInp = r"C:\Users\karimd\source\repos\AEC_Hackathon2021\query.txt"
#inputData = np.genfromtxt(pathInp)
scalerY = joblib.load('log\scalerY_A.pkl')
scalerX = joblib.load('log\scalerx_A.pkl')
# reshaping model
inputData_new = np.reshape(inputData, (1,5))
x_scaled = scalerX.transform(inputData_new)
prediction = model.predict(x_scaled)
#reshape or normalize here
y_scaled = scalerY.inverse_transform(prediction)
numPrediction = float(y_scaled[0][0])
#print(numPrediction)
#pathOut = r"Output\prediction.txt"
#np.savetxt(pathOut, y_scaled)
return numPrediction
# function option 2
def RunPredictionOp2(CO2,Type_B,Location_B,Area,Floors):
#Load saved model
model = tf.keras.models.load_model('log\LearnModel_B.h5')
model.summary()
# Input 1 - CO2 Emissions Numeical input
#CO2 = 2
# Input 2 - building type is 0 or 1
#Type_B = 1
# Input 3 - location 0 - 5
#Location_B = 3
# Input 4 - Total floor area
#Area = 100
# Input 5 - floorCount usually between 5 and 25
#Floors = 10
# Create 2d numpy array
inputData = np.array([[CO2], [Type_B], [Location_B], [Area], [Floors]])
#pathInp = r"query.txt"
#inputData = np.genfromtxt(pathInp)
#CHANGE THE FILE LOCATION!!
scalerB = joblib.load('log\scalerx_B.pkl')
# reshaping model
inputData_new = np.reshape(inputData, (1,5))
x_scaled = scalerB.transform(inputData_new)
y_pred = model.predict(x_scaled)
construction_type = y_pred.argmax(axis=1)
print("this is the construction type")
print(construction_type)
#NOT SURE IF THE FLOAT IS NECESSARY HERE
construction_type_unwarpped = construction_type[0]
print(construction_type_unwarpped)
# check which construction types each integer is
if construction_type_unwarpped == 0:
construction_type_string = "Concrete"
if construction_type_unwarpped == 1:
construction_type_string = "Steel-Concrete"
if construction_type_unwarpped == 2:
construction_type_string = "Wood"
if construction_type_unwarpped == 3:
construction_type_string = "Wood-Hybrid"
print(construction_type_string)
print(Area)
print(Floors)
#print(numPrediction)
#pathOut = r"C:\Users\karimd\source\repos\AEC_Hackathon2021\Output\prediction.txt"
#np.savetxt(pathOut, construction_type)
return construction_type_string