OmarRdev/Binary_Classification_HotelBookings
0
1import streamlit as st2import joblib3import numpy as np4 5# Load the trained model6model = joblib.load('model_voting_classifier.pkl')7 8# Streamlit app9def main():10 st.title('Hotel Reservation Cancellation App')11 st.write('This app predicts whether a customer cancels their hotel reservation based on input characteristics.')12 13 # Feature input names14 feature_names = [15 'Lead Time', 'Required Car Parking Spaces', 'Total Of Special Requests', 'Total Days On Hold',16 'Market Segment Groups', 'Distribution Chanel TA', 'Deposit Type Non Refund',17 ]18 19 # Collect user input20 user_inputs = {}21 for feature in feature_names:22 23 if feature in ['Market Segment Groups', 'Distribution Chanel TA', 'Deposit Type Non Refund']:24 user_input = st.checkbox(feature, key=feature)25 else:26 user_input = st.number_input(feature, min_value=0, max_value=500, value=0, key=feature, step=1)27 28 user_inputs[feature] = user_input29 30 31 # Add a "Submit" button32 if st.button('Submit'):33 # Check if all inputs are zero (no input)34 if all(v == 0 or v is False for v in user_inputs.values()):35 st.warning("No input provided. Please enter values.")36 37 else:38 # Prepare input for prediction39 input_data = np.array([[user_inputs[feature] for feature in feature_names]])40 41 # Make prediction42 prediction = model.predict(input_data)43 booking_hotel = "**Canceled**" if prediction[0] == 1 else "**No Canceled**"44 45 # Display prediction46 st.write('Predicted Booking Type:', booking_hotel)47 48if __name__ == '__main__':49 main()