Monday, October 4, 2021

Real Estate Price Prediction Using Machine Learning With GUI Using Tkinter

 Real Estate Price Prediction Using Machine Learning With GUI   Using Tkinter





  • Create a New Directory for your Project Using File Explorer

  1. First Install Anaconda from Anaconda | The World's Most Popular Data Science Platform Website.
  2. Now Open Sypder From Anaconda Navigator

    import pandas as pd

        df=pd.read_csv('data.csv')
          df = df.drop(columns=["No"])


                #checking if there is any missing value
                  #print(df.isnull().sum())

                      x= df.drop(columns=['Y house price of unit area'])
                        y=df['Y house price of unit area']

                            #changing string to numeric form
                              from sklearn.preprocessing import LabelEncoder
                                la=LabelEncoder()

                                    y=la.fit_transform(y)

                                        #scaling our independent data
                                          from sklearn.preprocessing import StandardScaler
                                            sc=StandardScaler()
                                              x=sc.fit_transform(x)

                                                  #train test split
                                                    from sklearn.model_selection import train_test_split
                                                      x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=42)

                                                          #          -------------------- END OF PRE-PROCESSING---------------------           #
                                                            from sklearn.metrics import r2_score
                                                              #Random Forest Regressor Model
                                                                from sklearn.ensemble import RandomForestRegressor
                                                                  rfc=RandomForestRegressor()
                                                                    rfc.fit(x_train,y_train)
                                                                      y_pred=rfc.predict(x_test)
                                                                        #checking accuracy
                                                                          print("Random Forest Classifier")
                                                                            print(r2_score(y_test, y_pred))

                                                                                #DUMPING MODELS

                                                                                from joblib import dump
                                                                                  dump(la,"price.joblib")
                                                                                    dump(sc,"scaling.joblib")
                                                                                      dump(rfc,"randomforest.joblib")

                                                                                      MAKING GUI USING TKINTER

                                                                                      import pandas as pd
                                                                                      from joblib import load
                                                                                      from tkinter import *
                                                                                      from tkinter import messagebox

                                                                                      sc=load("scaling.joblib")
                                                                                      rfc=load("randomforest.joblib")

                                                                                      def result():
                                                                                          try:
                                                                                              new=pd.DataFrame({"X1 transaction date":[float(a1.get())],"X2 house age":[float(a2.get())],"X3 distance to the nearest MRT station":[float(a3.get())],"X4 number of convenience stores":[float(a4.get())],"X5 latitude":[float(a5.get())],"X6 longitude":[float(a6.get())]})
                                                                                              new=sc.transform(new)
                                                                                              res=rfc.predict(new)
                                                                                              anslabel=Label(root,text='Price is',font=("Arial",10)).place(x=150,y=250)
                                                                                              ans=Label(root,text=res,font=('Arial',10)).place(x=200,y=250)
                                                                                              ans2=Label(root,text= "per unit area",font=("arial",10)).place(x=250,y=250)
                                                                                          except:
                                                                                              messagebox.showinfo("Error","Please fill all the values")


                                                                                      root=Tk()
                                                                                      root.geometry("400x300")
                                                                                      root.resizable(0,0)
                                                                                      root.title("Real Estate Prediction")

                                                                                      a1=StringVar()
                                                                                      a2=StringVar()
                                                                                      a3=StringVar()
                                                                                      a4=StringVar()
                                                                                      a5=StringVar()
                                                                                      a6=StringVar()

                                                                                      heading=Label(root,text="Real Estate Prediction System",font=("Arial",20),fg="PURPLE")
                                                                                      heading.place(x=10,y=5)

                                                                                      one=Label(root,text="Transaction date")
                                                                                      one.place(x=10,y=50)
                                                                                      two=Entry(root,textvariable=a1)
                                                                                      two.place(x=200,y=50)

                                                                                      three=Label(root,text="House age")
                                                                                      three.place(x=10,y=80)
                                                                                      four=Entry(root,textvariable=a2)
                                                                                      four.place(x=200,y=80)

                                                                                      five=Label(root,text="Distance to the nearest MRT station")
                                                                                      five.place(x=10,y=110)
                                                                                      six=Entry(root,textvariable=a3)
                                                                                      six.place(x=200,y=110)

                                                                                      seven=Label(root,text="Number of convenience stores")
                                                                                      seven.place(x=10,y=140)
                                                                                      eight=Entry(root,textvariable=a4)
                                                                                      eight.place(x=200,y=140)

                                                                                      nine=Label(root,text="Enter the Latitude")
                                                                                      nine.place(x=10,y=170)
                                                                                      ten=Entry(root,textvariable=a5)
                                                                                      ten.place(x=200,y=170)

                                                                                      nine=Label(root,text="Enter the Longitude")
                                                                                      nine.place(x=10,y=200)
                                                                                      ten=Entry(root,textvariable=a6)
                                                                                      ten.place(x=200,y=200)

                                                                                      submit=Button(root,text="PREDICT",bg="lightgrey",command=result,font=("Arial"),fg='black')
                                                                                      submit.place(x=10,y=250)

                                                                                      root.mainloop()

                                                                                      No comments:

                                                                                      Post a Comment

                                                                                      DRUG PREDICTTION USING MACHINE LEARNING WITH GUI USING TKINTER

                                                                                       DRUG PREDICTTION USING MACHINE LEARNING WITH GUI USING TKINTER Create a New Directory for your Project Using File Explorer Dataset -  Drug ...