-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
162 lines (113 loc) · 6.24 KB
/
main.py
File metadata and controls
162 lines (113 loc) · 6.24 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import tkinter as tk
from PIL import Image, ImageTk
import pickle
import pandas as pd
import warnings
import xgboost as xgb
import time
warnings.filterwarnings("ignore")
def input_variable_confirmation():
try:
int(property_size.get())
int(floor.get())
float(latitude.get())
float(longitude.get())
input_list_construct()
except ValueError:
answer.config(text= 'A wrong value was inserted')
def input_list_construct():
house_prf= {'size':int(property_size.get()), 'rooms':variablerooms.get(),'bathrooms':variablebathrooms.get(),'latitude':float(latitude.get()), 'longitude':float(longitude.get()),
'floorNumeric':int(floor.get()),'propertyType_duplex': 0, 'propertyType_flat': 0,'propertyType_penthouse':0,'propertyType_studio': 0}
propert = variableproperty.get()
if propert == 'duplex':
house_prf['propertyType_duplex'] += 1
elif propert == 'flat':
house_prf['propertyType_flat'] += 1
elif propert == 'penthouse':
house_prf['propertyType_penthouse'] += 1
elif propert == 'studio':
house_prf['propertyType_studio'] += 1
operationType = variableoperation.get()
prediction(house_profile= house_prf, operation=operationType)
def prediction(house_profile, operation):
if operation == 'rent':
model = pickle.load(open(r'C:\Users\Sebas\Documents\github\Project-5-scikitlearn\rent_model.sav','rb'))
df = pd.DataFrame(house_profile, index=[0])
model_predict = model.predict(df)
answer.config(text= f'The price is {model_predict[0]}')
elif operation== 'sale':
model = xgb.XGBRegressor()
model.load_model(r"C:\Users\Sebas\Documents\GitHub\Project-5-scikitlearn\sale_model.json")
df = pd.DataFrame(house_profile, index=[0])
model_predict = model.predict(df)
answer.config(text= f'The price is {model_predict[0]}')
def image_show():
img.show()
root = tk.Tk()
root.geometry('550x350')
root.title('Price predictor')
#white labels to give more space----------------------------------------------------------------------------------------------------------------------------------
white1 = tk.Label(root,text='').grid(row=1, column=0) #size
white2 = tk.Label(root,text='').grid(row=5, column=0) #coordinates
white3 = tk.Label(root,text='').grid(row=7, column=0) #coordinates
#Answer label-----------------------------------------------------------------------------------------------------------------------------------------------------
answer = tk.Label(root, text='')
answer.grid(row=17, column=1)
#Property size-----------------------------------------------------------------------------------------------------------------------------------------------------
L1 = tk.Label(root, text= 'Insert the property size').grid(row=0,column=0)
property_size = tk.Entry(root)
property_size.grid(row=0, column=1)
#coordinates-----------------------------------------------------------------------------------------------------------------------------------------------------
L2 = tk.Label(root, text='Insert the coordinates').grid(row=2, column=0)
#loading image
img = Image.open(r'C:\Users\Sebas\Documents\GitHub\Project-5-scikitlearn\Images\coord_find.png')
#load = load.resize((370, 201), Image.ANTIALIAS)
# setting image with the help of label
image_button = tk.Button(root, text='How can i find it?', command= image_show)
image_button.grid(row = 3, column = 0, columnspan = 1, rowspan = 2, padx = 5, pady = 5)
#Latitude and longitude
L3 = tk.Label(root,text='Latitude').grid(row=3, column=1)
latitude = tk.Entry(root)
latitude.grid(row=3, column=2)
L4 = tk.Label(root, text= 'Longitude').grid(row=4, column=1)
longitude = tk.Entry(root)
longitude.grid(row=4, column=2)
#floor-----------------------------------------------------------------------------------------------------------------------------------------------------
L5 = tk.Label(root, text = 'Insert the floor (If it\'s ground floor, insert 0)').grid(row=6, column=0)
floor = tk.Entry(root, validate= 'key')
floor.grid(row=6,column= 1)
#property type-----------------------------------------------------------------------------------------------------------------------------------------------------
L6 = tk.Label(root, text = 'Select the property type').grid(row=8, column=0)
properties = ['flat', 'duplex','penthouse','studio']
variableproperty = tk.StringVar(root)
variableproperty.set(properties[0])
propertyType = tk.OptionMenu(root, variableproperty, *properties)
propertyType.grid(row=8, column=1)
#operation-----------------------------------------------------------------------------------------------------------------------------------------------------
L7 = tk.Label(root, text = 'Select the operation').grid(row=9, column=0)
operationList = ['rent', 'sale']
variableoperation = tk.StringVar(root)
variableoperation.set('rent')
operation = tk.OptionMenu(root, variableoperation, *operationList)
operation.grid(row=9, column=1)
#rooms-----------------------------------------------------------------------------------------------------------------------------------------------------
L8 = tk.Label(root, text = 'Select the ammount of rooms').grid(row=10, column=0)
roomList = [0,1,2,3,4]
variablerooms = tk.IntVar(root)
variablerooms.set(roomList[0])
rooms = tk.OptionMenu(root, variablerooms, *roomList)
rooms.grid(row=10, column=1)
#bathrooms-----------------------------------------------------------------------------------------------------------------------------------------------------
L9 = tk.Label(root, text = 'Select the ammount of bathrooms').grid(row=11, column=0)
bathList = [1,2,3,4]
variablebathrooms = tk.IntVar(root)
variablebathrooms.set(bathList[0])
bathrooms = tk.OptionMenu(root, variablebathrooms, *bathList)
bathrooms.grid(row=11, column=1)
#Predict script----------------
predict_button = tk.Button(root, text='Predict', bg="#20bebe", fg='white', command= input_variable_confirmation)
predict_button.grid(row=17, column=0)
#Exit button-----------------------------------------------------------------------------------------------------------------------------------------------------
exit_button = tk.Button(root, text="Exit", bg="red",fg="white", command=root.destroy)
exit_button.grid(row=17, column=2)
root.mainloop()