2023-10-17 17:35:43 +02:00
|
|
|
from tkinter import *
|
|
|
|
from tkinter import messagebox
|
2023-10-17 18:36:06 +02:00
|
|
|
import pickle
|
|
|
|
import numpy as np
|
|
|
|
from sklearn.preprocessing import StandardScaler
|
2023-10-17 17:35:43 +02:00
|
|
|
|
|
|
|
window = Tk()
|
|
|
|
window.minsize(width=600, height=600)
|
|
|
|
window.config(padx=50, pady=50)
|
2023-10-17 18:10:27 +02:00
|
|
|
window.config(background="#ffffff")
|
2023-10-17 17:35:43 +02:00
|
|
|
window.title("Regresja")
|
|
|
|
|
2023-10-17 18:49:55 +02:00
|
|
|
canvas = Canvas(width=250, height=150, highlightthickness=0, background="#ffffff")
|
|
|
|
house = PhotoImage(file="house.png")
|
|
|
|
canvas.create_image(140,75, image=house)
|
|
|
|
canvas.grid(column=0, row=0, columnspan=2, padx=60)
|
2023-10-17 17:35:43 +02:00
|
|
|
|
|
|
|
tytul = Label()
|
2023-10-17 18:10:27 +02:00
|
|
|
tytul.config(text="Wycena wartości mieszkania na podstawie danych z serwisu otodom.pl", padx=70, pady=50, background="#ffffff")
|
2023-10-17 18:49:55 +02:00
|
|
|
tytul.grid(column=0, row=1, columnspan=2)
|
2023-10-17 17:35:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
metraz = Label()
|
2023-10-17 18:10:27 +02:00
|
|
|
metraz.config(text="Metraż", pady=20, background="#ffffff")
|
2023-10-17 18:49:55 +02:00
|
|
|
metraz.grid(column=0, row=2)
|
2023-10-17 17:35:43 +02:00
|
|
|
|
|
|
|
metraz_entry = Entry()
|
2023-10-17 18:49:55 +02:00
|
|
|
metraz_entry.grid(column=0, row=3)
|
2023-10-17 17:35:43 +02:00
|
|
|
|
|
|
|
pietro_entry = Entry()
|
2023-10-17 18:49:55 +02:00
|
|
|
pietro_entry.grid(column=1, row=3)
|
2023-10-17 17:35:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
pietro = Label()
|
2023-10-17 18:10:27 +02:00
|
|
|
pietro.config(text="Piętro", pady=20, background="#ffffff")
|
2023-10-17 18:49:55 +02:00
|
|
|
pietro.grid(column=1, row=2)
|
2023-10-17 17:35:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
przewidywania = Label()
|
2023-10-17 18:10:27 +02:00
|
|
|
przewidywania.config(text="Przewidywanie:", pady=20, padx=5, background="#ffffff")
|
2023-10-17 18:49:55 +02:00
|
|
|
przewidywania.grid(column=0, row=5, sticky='e')
|
2023-10-17 17:35:43 +02:00
|
|
|
|
2023-10-17 17:47:15 +02:00
|
|
|
wartosc_regresji = Label()
|
2023-10-17 18:10:27 +02:00
|
|
|
wartosc_regresji.config(text="Wartosć przewidywana", background="#ffffff")
|
2023-10-17 18:49:55 +02:00
|
|
|
wartosc_regresji.grid(column=1, row=5, sticky='w')
|
2023-10-17 17:35:43 +02:00
|
|
|
|
2023-10-17 18:36:06 +02:00
|
|
|
model = pickle.load(open("model.pkl", 'rb'))
|
2023-10-17 17:35:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
def val_numbers():
|
2023-10-17 18:04:34 +02:00
|
|
|
max_metraz = 100000
|
|
|
|
max_piętro = 100
|
2023-10-17 17:35:43 +02:00
|
|
|
metraz = metraz_entry.get()
|
|
|
|
pietro = pietro_entry.get()
|
|
|
|
if metraz == "" or not metraz.isdigit() or pietro=="" or not pietro.isdigit():
|
|
|
|
messagebox.showinfo(title="Error", message=f"Please provide valid data")
|
2023-10-17 18:04:34 +02:00
|
|
|
elif int(metraz) < 0 or int(metraz) > max_metraz or int(pietro) < 0 or int(pietro) > max_piętro:
|
|
|
|
messagebox.showinfo(title="Error", message=f"Please provide numbers between 0 to 100 for floors and 0 to 100.000 for metric area.")
|
2023-10-17 17:35:43 +02:00
|
|
|
else:
|
|
|
|
confirm = messagebox.askyesno(title="Confirm", message="Do you want to start prediction?")
|
2023-10-17 18:36:06 +02:00
|
|
|
if confirm == True:
|
|
|
|
array = np.array([[int(pietro_entry.get()),float(metraz_entry.get())]])
|
|
|
|
scaler = StandardScaler()
|
|
|
|
transformed_data = scaler.fit_transform(array)
|
|
|
|
prediction = model.predict(transformed_data)
|
|
|
|
wartosc_regresji.config(text=f'{round(prediction[0][0], 2)} PLN')
|
|
|
|
|
2023-10-17 17:35:43 +02:00
|
|
|
|
|
|
|
start_button = Button(command=val_numbers)
|
2023-10-17 18:10:27 +02:00
|
|
|
start_button.config(text="Start", background="#000000", foreground="#ffffff")
|
2023-10-17 18:49:55 +02:00
|
|
|
start_button.grid(column=0, row=4, columnspan=2, sticky="s", pady=20)
|
2023-10-17 17:35:43 +02:00
|
|
|
|
|
|
|
window.mainloop()
|
|
|
|
|
|
|
|
|