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