import streamlit as st import pandas as pd import numpy as np import pickle import json # load semua file yang telah disimpan with open('model_rfc.pkl', 'rb') as file_1: rfc = pickle.load(file_1) with open('model_scaler.pkl', 'rb') as file_2: scaler = pickle.load(file_2) with open('model_encoder.pkl', 'rb') as file_3: encoder = pickle.load(file_3) with open('list_num_cols.txt', 'r') as file_4: list_num_cols = json.load(file_4) with open('list_cat_cols.txt', 'r') as file_5: list_cat_cols = json.load(file_5) def run(): # membuat judul st.title('Booking Status Prediction') with st.form(key='Booking Status'): booking_id = st.text_input('Booking ID', value='') no_of_adults = st.number_input('Number of Adults', min_value=0, max_value=4, value=0, step=1) no_of_children = st.number_input('Number of Children', min_value=0, max_value=10, value=0, step=1) no_of_weekend_nights = st.number_input('Number of Weekend Nights',min_value=0, max_value=7, value=0, step=1 ) no_of_week_nights = st.number_input('Numer of Week Nights', min_value=0, max_value=17, value=0, step=1) type_of_meal_plan = st.selectbox('Type of Meal Plan',('Meal Plan 1','Not Selected','Meal Plan 2','Meal Plan 3'),index=1) required_car_parking_space = st.number_input('Required Car Parking Space', min_value=0, max_value=1, value=0, step=1) room_type_reserved = st.selectbox('Room Type Reserved',('Room_Type 1','Room_Type 2','Room_Type 3','Room_Type 4','Room_Type 5','Room_Type 6'),index=1) lead_time = st.number_input('Lead Time', min_value=0, max_value=500, value=0, step=1) arrival_year = st.number_input('Arrival Year', min_value=2017, max_value=2025, value=2017, step=1) arrival_month = st.number_input('Arrival Month', min_value=1, max_value=12, value=1, step=1) arrival_date= st.number_input('Arrival Date', min_value=1, max_value=31, value=26, step=1) market_segment_type = st.selectbox('Market Segment Type', ('Online','Aviation','Corporate','Offline'),index=1) repeated_guest= st.number_input('Repeated Guest', min_value=0, max_value=1, value=0, step=1) no_of_previous_cancellations= st.number_input('Number of Previous Cancellations', min_value=0, max_value=13, value=0, step=1) no_of_previous_bookings_not_canceled= st.number_input('Number of Previous Nookings Not Canceled', min_value=0, max_value=58, value=0, step=1) avg_price_per_room= st.number_input('Avarage Price Per Room', min_value=0, max_value=540, value=50, step=1) no_of_special_requests = st.number_input('Number of Special Requests', min_value=0, max_value=5, value=0, step=1) submitted = st.form_submit_button('Predict') # membuat data-set baru data_inf = { 'Booking_ID':booking_id, '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 , 'lead_time':lead_time, 'arrival_year':arrival_year, 'arrival_month':arrival_month, 'arrival_date':arrival_date, 'market_segment_type': market_segment_type, 'repeated_guest':repeated_guest, 'no_of_previous_cancellations':no_of_previous_cancellations, 'no_of_previous_bookings_not_canceled':no_of_previous_bookings_not_canceled, 'avg_price_per_room':avg_price_per_room, 'no_of_special_requests':no_of_special_requests } data_inf = pd.DataFrame([data_inf]) st.dataframe(data_inf) if submitted: # Split between Numerical Columns and Categorical Columns data_inf_num = data_inf[list_num_cols] data_inf_cat = data_inf[list_cat_cols] # Feature Scaling and Feature Encoding data_inf_num_scaled = scaler.transform(data_inf_num) data_inf_cat_encoded = encoder.transform(data_inf_cat) data_inf_final = np.concatenate((data_inf_num_scaled, data_inf_cat_encoded.toarray()), axis=1) # Predict y_pred_inf = rfc.predict(data_inf_final) prediction = 'Not Cancel' if y_pred_inf == 0 else 'Cancel' st.write('# Prediction: ', prediction) st.write('If the prediction shows "Cancel", there is a possibility that the booking will be canceled by the customer.') if __name__ == '__main__': run()