-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_input.py
54 lines (44 loc) · 2.25 KB
/
user_input.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
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
import csv
import joblib
province = input("Enter Alpha Code of Province: ")
provinces = ['Header', 'AB', 'BC', 'MB', 'NB', 'NL', 'NS', 'ON', 'PE', 'QC', 'SK']
R2scores = ['score', '94.02%', '73.28%', '96.25%', '81.63%', '89.22%', '70.57%', '92.92%', '96.01%', '75.97%', '96.81%']
CVscores = ['score', '64.20%', '-1.17%', '67.23%', '47.09%', '-133.87%', '-458.33%', '91.26%', '-188.63%', '38.17%', '-76.51%']
columns = ['prov', 'min_NoH', 'max_NoH', 'min_Pop', 'max_Pop', 'min_NoB', 'max_NoB', 'min_Disc', 'max_Disc']
# Get Required Row:
maxmin = open('Foresight/datasets/maxmin.csv')
maxmin = csv.reader(maxmin)
rows = []
for row in maxmin:
rows.append(row)
maxmin = rows[provinces.index(province)]
# Loading Models:
m1 = joblib.load('Foresight/models/' + province + '/m1.sav')
m2 = joblib.load('Foresight/models/' + province + '/m2.sav')
# Getting Inputs:
NoH = int(input("Enter of Homes: "))
Pop = int(input("Enter Population: "))
print()
# Output R2 & CV Scores:
print("R Squared Score: ", R2scores[provinces.index(province)])
print("Cross Validation Mean: ", CVscores[provinces.index(province)])
print()
# Normalization:
NoH = (NoH - int(maxmin[columns.index('min_NoH')])) / (int(maxmin[columns.index('max_NoH')]) - int(maxmin[columns.index('min_NoH')]))
Pop = (Pop - int(maxmin[columns.index('min_Pop')])) / (int(maxmin[columns.index('max_Pop')]) - int(maxmin[columns.index('min_Pop')]))
# Run Prediction:
dataframe1 = pd.DataFrame([[NoH, Pop]], columns = ['Number of Homes', 'Population'])
NoB = (m1.predict(dataframe1))[0][0]
dataframe2 = pd.DataFrame([[NoH, Pop, NoB]], columns = ['Number of Homes', 'Population', 'Number of Beds'])
Disc = (m2.predict(dataframe2))[0][0]
# Find Actual Prediction:
NoB = NoB * (int(maxmin[columns.index('max_NoB')]) - int(maxmin[columns.index('min_NoB')])) + int(maxmin[columns.index('min_NoB')])
Disc = Disc * (int(maxmin[columns.index('max_Disc')]) - int(maxmin[columns.index('min_Disc')])) + int(maxmin[columns.index('min_Disc')])
prediction = int(NoB + Disc)
# Output Values of M1, M2 & Prediction:
print("Predicted Number of Beds: ", NoB)
print("Predicted Adjustment: ", Disc)
print("Total Number of Beds Needed (with Adjustment): ", prediction)