ML Project – Restaurant Preference Classifier using Decision Tree
Machine Learning courses with 100+ Real-time projects Start Now!!
Program 1
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score ,classification_report
# Load Dataset
df_rest=pd.read_csv("D://scikit_data/rest/restaurant_preference.csv")
df_rest
df_rest.shape
df_rest.info()
df_rest.isnull().sum()
# Label Encoding
le=LabelEncoder()
df_rest['Cuisine_new']=le.fit_transform(df_rest['Cuisine'])
df_rest['MealTime_new']=le.fit_transform(df_rest['MealTime'])
df_rest['AgeGroup_new']=le.fit_transform(df_rest['AgeGroup'])
df_rest['Location_new']=le.fit_transform(df_rest['Location'])
df_rest['RestaurantType']=le.fit_transform(df_rest['RestaurantType'])
df_rest
df_rest.info()
df_rest=df_rest.drop(['Cuisine','MealTime','AgeGroup','Location'],axis='columns')
df_rest.info()
df_rest.head()
X = df_rest.drop('RestaurantType', axis=1)
y = df_rest['RestaurantType']
X
y
# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
len(X_train)
len(X_test)
model=DecisionTreeClassifier()
model.fit(X_train,y_train)
model.score(X_train,y_train)
y_pred=model.predict(X_test)
"Accuracy:", accuracy_score(y_test, y_pred)
print("\nClassification Report:\n", classification_report(y_test, y_pred))
df_rest
model.predict([[2,2,0,2]])
model.fit(X,y)
model.score(X,y)
model.predict([[1,1,2,2]])
cus=int(input("Enter Cuisine Type(Indian-0,Chinese-1,Italian-2,Mexican-3) :"))
mt=int(input("Enter MealTime(Breakfast-0,Dinner-1,Lunch-2) :"))
ag=int(input("Enter AgeGroup:(Adult-0,Senior-1,Teen-2) :"))
loc=int(input("Enter Location(Suburban-0,Rural-1,Urban-2) :"))
result=model.predict([[cus,mt,ag,loc]])
if(result==0):
print('Casual Dining')
elif(result==1):
print('Fast Food')
else:
print('Fine Dining')
Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

