Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
le=joblib.load('le_col.pkl')
|
| 8 |
+
mix=joblib.load('mimx_col.pkl')
|
| 9 |
+
lr=joblib.load('model.pkl')
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
le_col=['type_of_meal_plan','room_type_reserved','market_segment_type']
|
| 13 |
+
mimx_col=['no_of_adults','no_of_children','no_of_weekend_nights','no_of_week_nights','required_car_parking_space','lead_time','arrival_year','arrival_month','arrival_date','repeated_guest','no_of_previous_cancellations','no_of_previous_bookings_not_canceled','avg_price_per_room','no_of_special_requests']
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def prediction_Hotel_Customer_Churn_Model(no,of,w,n,t,r,s,l,a,aa,ad,ms,rg,oc,pb,av,sr):
|
| 20 |
+
try:
|
| 21 |
+
input_data=pd.DataFrame({
|
| 22 |
+
'no_of_adults':[no],
|
| 23 |
+
'no_of_children':[of],
|
| 24 |
+
'no_of_weekend_nights':[w],
|
| 25 |
+
'no_of_week_nights':[n],
|
| 26 |
+
'type_of_meal_plan':[t],
|
| 27 |
+
'required_car_parking_space':[r],
|
| 28 |
+
'room_type_reserved':[s],
|
| 29 |
+
'lead_time':[l],
|
| 30 |
+
'arrival_year':[a],
|
| 31 |
+
'arrival_month':[aa],
|
| 32 |
+
'arrival_date':[ad],
|
| 33 |
+
'market_segment_type':[ms],
|
| 34 |
+
'repeated_guest':[rg],
|
| 35 |
+
'no_of_previous_cancellations':[oc],
|
| 36 |
+
'no_of_previous_bookings_not_canceled':[pb],
|
| 37 |
+
'avg_price_per_room':[av],
|
| 38 |
+
'no_of_special_requests':[sr]
|
| 39 |
+
})
|
| 40 |
+
for col in le_col:
|
| 41 |
+
input_data[col]=le[col].transform(input_data[col])
|
| 42 |
+
input_data[mimx_col]=mix.transform(input_data[mimx_col])
|
| 43 |
+
prediction=lr.predict(input_data)
|
| 44 |
+
if prediction[0]==0:
|
| 45 |
+
return 'Not_Canceled'
|
| 46 |
+
else:
|
| 47 |
+
return 'Canceled'
|
| 48 |
+
except Exception as e:
|
| 49 |
+
return str(e)
|
| 50 |
+
gr.Interface(
|
| 51 |
+
inputs=[
|
| 52 |
+
gr.Number(label='no_of_adults'),
|
| 53 |
+
gr.Number(label='no_of_children'),
|
| 54 |
+
gr.Number(label='no_of_weekend_nights'),
|
| 55 |
+
gr.Number(label='no_of_week_nights'),
|
| 56 |
+
gr.Radio(['Meal Plan One', 'Not Selected', 'Meal Plan Two','Meal Plan Three'],label='type_of_meal_plan'),
|
| 57 |
+
gr.Number(label='required_car_parking_space'),
|
| 58 |
+
gr.Radio(['Room_Type 1', 'Room_Type 4', 'Room_Type 2', 'Room_Type 6','Room_Type 5', 'Room_Type 7', 'Room_Type 3'],label='room_type_reserved'),
|
| 59 |
+
gr.Number(label='lead_time'),
|
| 60 |
+
gr.Number(label='arrival_year'),
|
| 61 |
+
gr.Number(label='arrival_month'),
|
| 62 |
+
gr.Number(label='arrival_date'),
|
| 63 |
+
gr.Radio(['Offline', 'Online', 'Corporate', 'Aviation', 'Complementary'],label='market_segment_type'),
|
| 64 |
+
gr.Number(label='repeated_guest'),
|
| 65 |
+
gr.Number(label='no_of_previous_cancellations'),
|
| 66 |
+
gr.Number(label='no_of_previous_bookings_not_canceled'),
|
| 67 |
+
gr.Number(label='avg_price_per_room'),
|
| 68 |
+
gr.Number(label='no_of_special_requests')
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
],
|
| 72 |
+
fn=prediction_Hotel_Customer_Churn_Model,
|
| 73 |
+
outputs=gr.Textbox(label='Prediction'),
|
| 74 |
+
title='Prediction Program',
|
| 75 |
+
description='This App for work predict the Customer in hotel Not_Canceled or Canceled Booking'
|
| 76 |
+
).launch()
|