p1-m2-ftds-rmt-18 / prediction.py
mukhlishr's picture
Update prediction.py
d83e1f2
raw
history blame
2.85 kB
import streamlit as st
import pandas as pd
import pickle
# Load All Files
with open('grid_rfc_best.pkl', 'rb') as file_1:
grid_rfc_best = pickle.load(file_1)
# bikin fungsi
def run():
with st.form(key='Reserved_data'):
no_of_adults = st.selectbox('adult(s)', (1,2,3,4,5,6,7,8), index=1, help='How many adults will stay')
no_of_children = st.selectbox('children', (0,1,2,3,4), index=0, help='How many adults will stay')
no_of_weekend_nights = st.selectbox('Weekend Night', (0,1,2,3,4,5,6,7,8,9,10), index=1, help='How many Night will stay at weekend')
no_of_week_nights = st.number_input('Weekdays Night', min_value=0, max_value=20, value=1, help='How many Night will stay at weekdays')
type_of_meal_plan = st.selectbox('Type of Meal', (1,2,3,4), index=1, help='1 = type 1 \n 2 = type 2 \n 3 = type 3 \n 4 = Not Selected')
required_car_parking_space = st.radio('Car Parking', (0, 1), index=1, help='0 = No \n 1 = Yes')
room_type_reserved = st.selectbox('Room Type', (1,2,3,4,5,6,7), index=1)
arrival_month = st.selectbox('Arrival Month', (1,2,3,4,5,6,7,8,9,10,11,12), index=1)
market_segment_type = st.radio('Source order', (1, 2, 3, 4, 5), index=1, help='1=online \n 2=offline \n 3=corporate \n 4=complementary \n 5=aviation')
no_of_previous_cancellations = st.selectbox('History Cancel', (0,1,2,3,4,5,6,7,8,9,10), index=0)
no_of_special_requests = st.selectbox(' Special Request', (0,1,2,3,4,5), index=0)
binned_lead_time = st.radio('Lead time', (1, 2, 3, 4, 5,6), index=1, help='1= <3 days \n 2= 3-7 days \n 3= 7-14 days \n 4= 14-30 days \n 5=30-90 days \n 6= >90 days')
binned_no_cancel = st.radio('History not Cancel', (0,1), index=1)
binned_price = st.radio('Type of Price', (1, 2, 3), index=1, help='1 = low \n 2 = medium \n 3 = high')
st.markdown('---')
submitted = st.form_submit_button('Predict')
data_inf = {
'no_of_adults': no_of_adults,
'no_of_children':no_of_children,
'no_of_weekend_nights' :no_of_weekend_nights,
'no_of_week_nights':no_of_week_nights,
'type_of_meal_plan':type_of_meal_plan,
'required_car_parking_space': required_car_parking_space,
'room_type_reserved': room_type_reserved,
'arrival_month': arrival_month,
'market_segment_type' : market_segment_type,
'no_of_previous_cancellations' : no_of_previous_cancellations,
'no_of_special_requests' : no_of_special_requests,
'binned_lead_time' : binned_lead_time,
'binned_no_cancel' : binned_no_cancel,
'binned_price': binned_price
}
data_inf = pd.DataFrame([data_inf])
st.dataframe(data_inf)
if submitted:
# Predict using grid_rfc
y_pred_inf = grid_rfc_best.predict(data_inf)
st.write('# Cancelation: ', str(int(y_pred_inf)))
if __name__ == '__main__':
run()