You are on page 1of 8

Hotel Grand Central by Anuraag Rath - Jupyter Notebook http://localhost:8888/notebooks/Hotel Grand Central by Anur...

Machine Learning implementation


by Anuraag Rath
Hotal Grand Central Customers purchase Dataset
In [93]: from IPython import display
display.Image("./HGC.jpg")
Out[93]:

In [1]: import pandas as pd


import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

from sklearn.model_selection import train_test_split


from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

In [2]: dataHotel = pd.read_csv("DataHotel.csv", skipinitialspace=True)


dataHotel
Out[2]:
Unnamed:
customer_id pay daysSpent bathService RoomType minForService floor
0

Business
0 0 2869 3600 1 2 4 1
Rooms

Business
1 1 4318 3900 1 2 4 9
Rooms
Business
2 2 6265 2700 1 1 4 2
Rooms

59
Hotel Grand Central by Anuraag Rath - Jupyter Notebook http://localhost:8888/notebooks/Hotel Grand Central by Anur...

Unnamed:
customer_id pay daysSpent bathService RoomType minForService floor
0

Super
3 3 24 4900 1 1 2 3
Deluxe
Business
4 4 9481 3900 1 1 3 4
Rooms

... ... ... ... ... ... ... ... ...

Business
1008 1008 7329 2300 1 1 5 2
Rooms
Business
1009 1009 10286 3750 1 2 1 1
Rooms

1010 1010 9169 4000 1 1 Deluxe 5 1

Super
1011 1011 1721 4200 1 2 2 5
Deluxe

Executive
1012 1012 1676 18000 2 2 2 5

In [3]: #Mapping the Features


roomType = {"Business Rooms": 1, "Deluxe": 2, "Super Deluxe": 3, "Execu
dataHotel["RoomType"] = dataHotel["RoomType"].map(roomType)
#dataHotel["RoomType"] = dataHotel["RoomType"].astype(int)

dataHotel
Out[3]:
Unnamed:
customer_id pay daysSpent bathService RoomType minForService floor
0

0 0 2869 3600 1 2 1 4 1

1 1 4318 3900 1 2 1 4 9

2 2 6265 2700 1 1 1 4 2

3 3 24 4900 1 1 3 2 3

4 4 9481 3900 1 1 1 3 4

... ... ... ... ... ... ... ... ...

1008 1008 7329 2300 1 1 1 5 2

1009 1009 10286 3750 1 2 1 1 1

1010 1010 9169 4000 1 1 2 5 1

1011 1011 1721 4200 1 2 3 2 5

1012 1012 1676 18000 2 2 4 2 5

1013 rows × 16 columns

In [4]: ouiNon = {"Yes": 1, "No": 0}

dataHotel["Damages"] = dataHotel["Damages"].map(ouiNon)

dataHotel["spa"] = dataHotel["spa"].map(ouiNon)

dataHotel["has_washer_dryer"] = dataHotel["has_washer_dryer"].map(ouiNo

dataHotel["has_personalizedService"] = dataHotel["has_personalizedServi

dataHotel["barservice"] = dataHotel["barservice"].map(ouiNon)

dataHotel["has_dishwasher"] = dataHotel["has_dishwasher"].map(ouiNon)

dataHotel["has_patio"] = dataHotel["has_patio"].map(ouiNon)

dataHotel["has_gym"] = dataHotel["has_gym"].map(ouiNon)

60
Hotel Grand Central by Anuraag Rath - Jupyter Notebook http://localhost:8888/notebooks/Hotel Grand Central by Anur...

dataHotel
Out[4]:
Unnamed:
customer_id pay daysSpent bathService RoomType minForService floor
0

0 0 2869 3600 1 2 1 4 1

1 1 4318 3900 1 2 1 4 9

2 2 6265 2700 1 1 1 4 2

3 3 24 4900 1 1 3 2 3

4 4 9481 3900 1 1 1 3 4

... ... ... ... ... ... ... ... ...

1008 1008 7329 2300 1 1 1 5 2

1009 1009 10286 3750 1 2 1 1 1

1010 1010 9169 4000 1 1 2 5 1

1011 1011 1721 4200 1 2 3 2 5

1012 1012 1676 18000 2 2 4 2 5

1013 rows × 16 columns

In [5]: hotelDataMain = dataHotel.drop(["Unnamed: 0", "customer_id"], axis = 1)


hotelDataMain.head()
Out[5]:
pay daysSpent bathService RoomType minForService floor Damages spa has_washer_d

0 3600 1 2 1 4 1 1 1

1 3900 1 2 1 4 9 0 1

2 2700 1 1 1 4 2 0 1

3 4900 1 1 3 2 3 0 1

4 3900 1 1 1 3 4 1 1

61
Hotel Grand Central by Anuraag Rath - Jupyter Notebook http://localhost:8888/notebooks/Hotel Grand Central by Anur...

In [10]: X = hotelDataMain[["daysSpent",
"bathService",
"RoomType",
"minForService",
"floor",
"Damages",
"spa",
"has_washer_dryer",
"has_personalizedService",
"barservice",
"has_dishwasher",
"has_patio",
"has_gym"]]

y = hotelDataMain["pay"]

correlationMatrix = hotelDataMain.corr()
top_corr_features = correlationMatrix.index
plt.figure(figsize=(20,20))

heatMap = sns.heatmap(hotelDataMain[top_corr_features].corr(),annot=Tru

In [17]: #Correlation Scatter plots

62
Hotel Grand Central by Anuraag Rath - Jupyter Notebook http://localhost:8888/notebooks/Hotel Grand Central by Anur...

plt.scatter(hotelDataMain["floor"], hotelDataMain.pay)
plt.xlabel('Floor')
plt.ylabel('Bill Amount')
plt.show()

In [20]: plt.scatter(hotelDataMain["RoomType"], hotelDataMain.pay)


plt.xlabel("""RoomType
{1:Business,
2:Deluxe,
3:SuperDeluxe,
4:ExecutiveDeluxe}""")
plt.ylabel('Bill Amount')
plt.show()

63
Hotel Grand Central by Anuraag Rath - Jupyter Notebook http://localhost:8888/notebooks/Hotel Grand Central by Anur...

In [25]: # Correlation Scatter plots


plt.scatter(hotelDataMain["minForService"], hotelDataMain.pay)
plt.xlabel('minForService')
plt.ylabel('Bill Amount')
plt.show()

Machine Learning Implementation

-------------------------------------------------

Linear Regression
In [85]: Xfeatures = hotelDataMain[["daysSpent",
"bathService",
"RoomType",
"has_washer_dryer",
"has_personalizedService",
"barservice",
"has_gym"]]
yFeature = hotelDataMain.pay

xTrain, xTest, yTrain, yTest = train_test_split(Xfeatures,


yFeature,
train_size = 0.8,
test_size = 0.2, random

hotelRegression = LinearRegression()
hotelRegression.fit(xTrain, yTrain)
predictPrices = hotelRegression.predict(xTest)
predictPrices
Out[85]:

64
Hotel Grand Central by Anuraag Rath - Jupyter Notebook http://localhost:8888/notebooks/Hotel Grand Central by Anur...

array([2356.04125745, 3325.78080685, 4337.12716716, 2356.04125745,


2356.04125745, 2356.04125745, 2356.04125745, 3731.30607783,
3325.78080685, 3325.78080685, 3175.52066495, 3325.78080685,
2356.04125745, 3325.78080685, 2356.04125745, 2356.04125745,
2356.04125745, 5849.28962962, 3325.78080685, 3325.78080685,
2356.04125745, 3325.78080685, 2356.04125745, 3325.78080685,
3155.29915627, 3325.78080685, 5093.20839839, 2356.04125745,
2356.04125745, 2356.04125745, 2356.04125745, 4487.38730906,
2356.04125745, 2356.04125745, 5093.20839839, 2356.04125745,
2356.04125745, 3325.78080685, 2356.04125745, 2356.04125745,
3325.78080685, 2356.04125745, 3325.78080685, 2356.04125745,
3175.52066495, 3325.78080685, 3325.78080685, 3325.78080685,
3325.78080685, 3325.78080685, 5498.73366937, 2356.04125745,
2356.04125745, 4687.68312741, 2356.04125745, 2761.56652842,
2356.04125745, 2356.04125745, 3325.78080685, 5093.20839839,
2356.04125745, 2356.04125745, 3731.30607783, 2356.04125745,
3731.30607783, 5093.20839839, 5093.20839839, 2356.04125745,
2761.56652842, 2356.04125745, 2356.04125745, 3731.30607783,
3155.29915627, 4687.68312741, 5093.20839839, 3731.30607783,
2356.04125745, 3325.78080685, 2272.33123244, 2356.04125745,
2356.04125745, 3325.78080685, 3325.78080685, 2356.04125745,
5093.20839839, 3155.29915627, 2356.04125745, 4687.68312741,
4687.68312741, 1950.51598647, 4687.68312741, 5093.20839839,
4687.68312741, 2292.55274113, 4687.68312741, 2356.04125745,
2356.04125745, 2356.04125745, 3325.78080685, 3325.78080685,
3325.78080685, 3325.78080685, 2356.04125745, 4687.68312741,
2356.04125745, 3325.78080685, 5093.20839839, 3325.78080685,
3346.00231554, 3325.78080685, 2356.04125745, 2356.04125745,
2356.04125745, 2356.04125745, 2356.04125745, 2185.55960686,
5093.20839839, 2356.04125745, 2185.55960686, 3911.3803875 ,
2185.55960686, 2356.04125745, 3731.30607783, 3325.78080685,
5093.20839839, 2761.56652842, 3731.30607783, 2356.04125745,
3175.52066495, 2356.04125745, 4687.68312741, 2356.04125745,
6660.34017157, 5849.28962962, 2356.04125745, 2356.04125745,
3325.78080685, 5498.73366937, 2356.04125745, 4687.68312741,
5093.20839839, 5093.20839839, 5093.20839839, 3155.29915627,

In [87]: theScore = hotelRegression.score(xTrain, yTrain)


print("Accuracy of Model:", theScore)
Accuracy of Model: 0.8557101791261511

Predict price
In [81]: yourName = "Anuraag Rath"

daysSpentu = 1
yourbathService = 2
yourroomType = 2
washer_dryer = 1
personalizedService = 0
yourbarservice = 1
gymService = 1

myOptions = [[daysSpentu, yourbathService, yourroomType, washer_dryer,

predictMyPrice = hotelRegression.predict(myOptions)

print("Mr. {name}, your Bill amount is Rs. {price}".format(name = yourN

Mr. Anuraag Rath, your Bill amount is Rs. [4507.60881774]

65
Hotel Grand Central by Anuraag Rath - Jupyter Notebook http://localhost:8888/notebooks/Hotel Grand Central by Anur...

The Machine Learning Model has been created

66

You might also like