Monday, October 4, 2021

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 200.csv
Background Image - img
  1. First Install Anaconda from Anaconda | The World's Most Popular Data Science Platform Website.
  2. Now Open Sypder From Anaconda Navigator

CREATING BACKEND FILE [MAIN.PY]

import pandas as pd

df=pd.read_csv('drug200.csv')
#checking if there is any missing value

#print(df.isnull().sum())

x=df.iloc[0:201,0:5]#independent
y=df["Drug"]#dependent

from sklearn.preprocessing import LabelEncoder
la=LabelEncoder()
y=la.fit_transform(y)

ls=LabelEncoder()
x["Sex"]=ls.fit_transform(x["Sex"])

lb=LabelEncoder()
x["BP"]=lb.fit_transform(x["BP"])

lc=LabelEncoder()
x["Cholesterol"]=lc.fit_transform(x["Cholesterol"])

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

#train test
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=0)

#RandomForestClassifier
from sklearn.ensemble import RandomForestClassifier
lr=RandomForestClassifier()
lr.fit(x_train,y_train)
y_pred=lr.predict(x_test)

#checking accuracy
from sklearn.metrics import accuracy_score
print("Accuracy Score is:")
print(accuracy_score(y_test, y_pred))

#saving models
from joblib import dump
dump(la,"Drug.joblib")
dump(ls,"Sex.joblib")
dump(lb,"BP.joblib")
dump(lc,"Cholesterol.joblib")
dump(sc,"scaling.joblib")
dump(lr,"regressor.joblib")


GUI USING TKINTER


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

la=load("Drug.joblib")
ls=load("Sex.joblib")
lb=load("BP.joblib")
lc=load("Cholesterol.joblib")
sc=load("scaling.joblib")
lr=load("regressor.joblib")

def result():
    new=pd.DataFrame({"Age":[(int(a1.get()))],"Sex":[(a2.get())],"BP":[(a3.get())],"Cholesterol":[(a4.get())],"Na_to_K":[(float(a5.get()))]})
    new["Sex"]=ls.transform(new["Sex"])
    new["BP"]=lb.transform(new["BP"])
    new["Cholesterol"]=lc.transform(new["Cholesterol"])
    new=sc.transform(new)
    o=lr.predict(new)
    if o==0:
        drug=Label(root,text="Required Drug is [DrugY]",font=("arial",20),fg="white",bg="violet")
        drug.place(x=10,y=300)
    elif o==1:
        drug=Label(root,text="Required Drug is [drugA]",font=("arial",20),fg="white",bg="red")
        drug.place(x=10,y=300)
    elif o==2:
        drug=Label(root,text="Required Drug is [drugB]",font=("arial",20),fg="white",bg="green")
        drug.place(x=10,y=300)
    elif o==3:
        drug=Label(root,text="Required Drug is [drugC]",font=("arial",20),fg="white",bg="orange")
        drug.place(x=10,y=300)
    else:
        drug=Label(root,text="Required Drug is [drugX]",font=("arial",20),fg="white",bg="black")
        drug.place(x=10,y=300)
root=Tk()
root.geometry("1000x400")
root.resizable(0,0)
root.title("Drug Prediction")
a1=StringVar()
a2=StringVar()
a3=StringVar()
a4=StringVar()
a5=StringVar()

heading=Label(root,text="Drug Prediction Using ML",font=("Arial",25),fg="darkblue")
heading.place(x=0,y=10)

age=Label(root,text="Enter the Age")
age.place(x=10,y=80)
age1=Entry(root,textvariable=a1)
age1.place(x=250,y=80)

sex=Label(root,text="Enter the Gender(M/F)")
sex.place(x=10,y=110)
sex1=Entry(root,textvariable=a2)
sex1.place(x=250,y=110)

bp=Label(root,text="Enter the BP (HIGH/NORMAL/LOW)")
bp.place(x=10,y=140)
bp1=Entry(root,textvariable=a3)
bp1.place(x=250,y=140)

Cholesterol=Label(root,text="Enter the Cholesterol level(HIGH/NORMAL) ")
Cholesterol.place(x=10,y=170)
Cholesterol1=Entry(root,textvariable=a4)
Cholesterol1.place(x=250,y=170)

Na_to_K=Label(root,text="Enter the Na to K value")
Na_to_K.place(x=10,y=200)
Na_to_K1=Entry(root,textvariable=a5)
Na_to_K1.place(x=250,y=200)

submit=Button(root,text="Predict",command=result,font=("Arial",20),fg="white",bg="red")
submit.place(x=250,y=230)

bg = PhotoImage(file = r"img.png")

# Show image using label
label2 = Labelrootimage = bg)
label2.place(x = 500y = 0)
root.mainloop()

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()

                                                                                      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 ...