Dummy Variables in Machine Learning
Free Machine Learning courses with 130+ real-time projects Start Now!!
Program 1
import pandas as pd # Version 2.2.2 import numpy as np # Version 1.24.3 import matplotlib.pyplot as plt # Version 3.7.1 import os from sklearn import linear_model # 1.5.11import df=pd.read_csv("D://scikit_data\home/homeprices.csv") print(df) df_dummi=pd.get_dummies(df.town) print(df_dummi) new_df=pd.concat([df,df_dummi],axis='columns') #new_df=new_df.drop(['town'],axis='columns') new_df.drop(['town','Shalimar'],axis='columns',inplace=True) print(new_df) M=new_df.drop('price',axis='columns') # independed variables print(M) N=new_df.price print(N) model=linear_model.LinearRegression() model.fit(M,N) print(model) x=int(input("Enter Area for Predication: ")) os.system('cls') print("Predication Price of Shlimar Town Ship",model.predict([[x,False,False]])) print("Predication Price of DbPride Town Ship",model.predict([[x,False,True]])) print("Predication Price of Aamrpal Town Ship",model.predict([[x,True,False]]))
Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google